Java Code Examples for com.jolbox.bonecp.BoneCPConfig#setMinConnectionsPerPartition()

The following examples show how to use com.jolbox.bonecp.BoneCPConfig#setMinConnectionsPerPartition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionPool.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public ConnectionPool(String dbcUrl, String user, String pass, int minConns,
		int maxConns, int partCount) throws ClassNotFoundException, SQLException {
	/*
	 * Initialize our connection pool.
	 * 
	 * We'll use a connection pool and reuse connections on a per-thread basis. 
	 */
			
	/* setup the connection pool */
	BoneCPConfig config = new BoneCPConfig();
	config.setJdbcUrl(dbcUrl); 
	config.setUsername(user); 
	config.setPassword(pass);
	config.setMinConnectionsPerPartition(minConns);
	config.setMaxConnectionsPerPartition(maxConns);
	config.setPartitionCount(partCount);
	// Enable only for debugging.
	//config.setCloseConnectionWatch(true);
	
	pool = new BoneCP(config);
}
 
Example 2
Source File: MysqlUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the connection pool.
 */
public static final void init(String database, String username, String password, 
		String server, int maxConn, int minConn, String jndi) {
	String dbUrl = StringUtil.concat("jdbc:mysql://", server, ":3306/", database, 
			"?connectTimeout=", 10000, "&useUnicode=true&characterEncoding=utf8");
	
	logger.info("Try to connect to Mysql with url: {}", dbUrl);
	
  // create a new configuration object
 	BoneCPConfig config = new BoneCPConfig();
  // set the JDBC url
 	config.setJdbcUrl(dbUrl);
 	config.setPartitionCount(2);
 	config.setMaxConnectionsPerPartition(maxConn);
 	config.setMinConnectionsPerPartition(minConn);
 	config.setUsername(username);
 	config.setPassword(password);
	
  // setup the connection pool
	try {
		BoneCPDataSource dataSource = new BoneCPDataSource(config);
		Context jndiContext = GameContext.getInstance().getJndiContext();
		jndiContext.bind(jndi, dataSource);
		dataSourceMap.put(jndi, dataSource);
		dataSourceReadyMap.put(jndi, Boolean.TRUE);
	} catch (Exception e) {
		logger.warn("The connection to Mysql database is unavailable. Exception:{}", e.getMessage());
		dataSourceReadyMap.put(jndi, Boolean.FALSE);
	}
}
 
Example 3
Source File: DbTest.java    From netcrusher-java with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    reactor = new NioReactor();

    crusher = TcpCrusherBuilder.builder()
            .withReactor(reactor)
            .withBindAddress("127.0.0.1", CRUSHER_PORT)
            .withConnectAddress("127.0.0.1", DB_PORT)
            .buildAndOpen();

    hsqlServer = new Server();
    hsqlServer.setAddress("127.0.0.1");
    hsqlServer.setPort(DB_PORT);
    hsqlServer.setDaemon(true);
    hsqlServer.setErrWriter(new PrintWriter(System.err));
    hsqlServer.setLogWriter(new PrintWriter(System.out));
    hsqlServer.setNoSystemExit(true);
    hsqlServer.setDatabasePath(0, "mem:testdb");
    hsqlServer.setDatabaseName(0, "testdb");
    hsqlServer.start();

    Class.forName("org.hsqldb.jdbc.JDBCDriver");

    BoneCPConfig config = new BoneCPConfig();
    config.setJdbcUrl(String.format("jdbc:hsqldb:hsql://127.0.0.1:%d/testdb", CRUSHER_PORT));
    config.setUsername("sa");
    config.setPassword("");
    config.setInitSQL(SQL_CHECK);
    config.setConnectionTestStatement(SQL_CHECK);
    config.setAcquireIncrement(1);
    config.setAcquireRetryAttempts(1);
    config.setAcquireRetryDelayInMs(1000);
    config.setConnectionTimeoutInMs(1000);
    config.setQueryExecuteTimeLimitInMs(1000);
    config.setDefaultAutoCommit(false);
    config.setDefaultReadOnly(true);
    config.setDefaultTransactionIsolation("NONE");
    config.setPartitionCount(1);
    config.setMinConnectionsPerPartition(1);
    config.setMaxConnectionsPerPartition(1);
    config.setLazyInit(true);
    config.setDetectUnclosedStatements(true);

    connectionPool = new BoneCP(config);
}