本文整理汇总了Java中com.jolbox.bonecp.BoneCPConfig.setMinConnectionsPerPartition方法的典型用法代码示例。如果您正苦于以下问题:Java BoneCPConfig.setMinConnectionsPerPartition方法的具体用法?Java BoneCPConfig.setMinConnectionsPerPartition怎么用?Java BoneCPConfig.setMinConnectionsPerPartition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jolbox.bonecp.BoneCPConfig
的用法示例。
在下文中一共展示了BoneCPConfig.setMinConnectionsPerPartition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConfig
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private BoneCPConfig createConfig() {
final BoneCPConfig config = new BoneCPConfig();
config.setPartitionCount(1);
config.setLazyInit(false);
config.setMinConnectionsPerPartition(3);
config.setMaxConnectionsPerPartition(3);
config.setDatasourceBean(new AbstractDataSource() {
@Override
public Connection getConnection() throws SQLException {
return Mockito.mock(Connection.class);
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return getConnection();
}
public Logger getParentLogger() {
return null;
}
});
config.setConnectionTimeoutInMs(Timeout.standardTimeoutMillis());
config.setConnectionHook(new BoneCPHack(config.getConnectionHook()));
return config;
}
示例2: BoneCPDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
public BoneCPDataSource(ConfigMap<String, String> datasource) throws IOException {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(datasource.get("url"));
config.setUsername(datasource.get("user"));
config.setPassword(datasource.get("password"));
config.setMinConnectionsPerPartition(datasource.getInteger("min_pool_size", 1));
config.setMaxConnectionsPerPartition(datasource.getInteger("max_pool_size", 10));
config.setPartitionCount(datasource.getInteger("partition_size", 1));
try {
this.datasource = new BoneCP(config);
} catch (SQLException e) {
throw new IOException(e);
}
}
示例3: ConnectionPool
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
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);
}
示例4: run
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
@Override
public void run(KenshoConfiguration configuration,
Environment environment) throws ClassNotFoundException {
final BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(configuration.getDataSourceFactory().getUrl());
config.setUsername(configuration.getDataSourceFactory().getUser());
config.setPassword(configuration.getDataSourceFactory().getPassword());
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(2);
config.setPartitionCount(1);
try {
final BoneCP connectionPool = new BoneCP(config);
final PgStatus status = new PgStatus(connectionPool);
final StatsEngine statsEngine = new StatsEngine(status);
environment.jersey().register(new DashboardResource(statsEngine));
environment.jersey().register(new DataResource(statsEngine));
environment.jersey().register(new QueryResource());
} catch (SQLException e) {
System.exit(0);
e.printStackTrace();
}
}
示例5: BigCloneBenchDB
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private BigCloneBenchDB() throws SQLException {
BoneCPConfig config = new BoneCPConfig();
Path db = Paths.get("bigclonebenchdb/bcb").toAbsolutePath();
config.setJdbcUrl("jdbc:h2:" + db.toString());
config.setUsername("sa");
config.setPassword("");
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
}
示例6: ToolsDB
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private ToolsDB() throws SQLException {
BoneCPConfig config = new BoneCPConfig();
Path db = Paths.get("toolsdb/tools").toAbsolutePath();
config.setJdbcUrl("jdbc:h2:" + db.toString());
config.setUsername("sa");
config.setPassword("bigclonebencheval");
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
}
示例7: getDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
public DataSource getDataSource()
throws ClassNotFoundException
{
if (!isInited)
{
lock.lock();
try
{
if (!isInited)
{
Class.forName(getDriver());
boneCPConfig = new BoneCPConfig();
boneCPConfig.setJdbcUrl(getUrl());
boneCPConfig.setUsername(getUsername());
boneCPConfig.setPassword(getPassword());
// ����ÿ60�������ݿ��еĿ���������
boneCPConfig.setIdleConnectionTestPeriod(idleConnectionTestPeriod, TimeUnit.MINUTES);
// �������ӿ���ʱ��
boneCPConfig.setIdleMaxAge(idleMaxAge, TimeUnit.MINUTES);
boneCPConfig.setPartitionCount(partitionCount);
// ����ÿ�������е����������
boneCPConfig.setMaxConnectionsPerPartition(maxConnectionsPerPartition);
// ����ÿ�������е���С������
boneCPConfig.setMinConnectionsPerPartition(minConnectionsPerPartition);
// �����ӳ��е����Ӻľ���ʱ�� BoneCPһ��ͬʱ��ȡ��������
boneCPConfig.setAcquireIncrement(acquireIncrement);
// �����ͷŴ���
boneCPConfig.setReleaseHelperThreads(releaseHelperThreads);
ds = new BoneCPDataSource(boneCPConfig);
isInited = true;
}
}
finally
{
lock.unlock();
}
}
return ds;
}
示例8: init
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
/**
* 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);
}
}
示例9: createBoneCP
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private void createBoneCP() {
try {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(String.format("jdbc:mysql://%s:%d/%s", this.host, this.port, this.database));
config.setUsername(this.username);
config.setPassword(this.password);
config.setPartitionCount(2);
config.setMinConnectionsPerPartition(this.minPoolSize);
config.setMaxConnectionsPerPartition(this.maxPoolSize);
boneCP = new BoneCP(config);
this.createConnection();
} catch (Exception ex) {
throw new Error("Unrecoverable error when creating the BoneCP object.", ex);
}
}
示例10: DBPool
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
/**
* 创建一个数据库连接池
* @param poolName
* @param host
* @param port
* @param dbName
* @param username
* @param password
* @param partitionCount
* @param minConnCountPerPar
* @param maxConnCountPerPar
* @throws Exception
*/
protected DBPool(String poolName, String host, String port, String dbName, String username, String password, int partitionCount, int minConnCountPerPar,
int maxConnCountPerPar) throws Exception
{
dbUrl = String.format(URL, host, port, dbName);
this.poolName = poolName;
this.partitionCount = partitionCount;
this.maxConnCountPerPar = maxConnCountPerPar;
this.minConnCountPerPar = minConnCountPerPar;
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(dbUrl);
config.setUsername(username);
config.setPassword(password);
// 分区数
config.setPartitionCount(partitionCount);
// 每次创建的新连接个数
config.setAcquireIncrement(2);
// 处理释放后的conn线程数
config.setReleaseHelperThreads(3);
// 分区最大连接数
config.setMaxConnectionsPerPartition(maxConnCountPerPar);
// 分区最小连接数
config.setMinConnectionsPerPartition(minConnCountPerPar);
// 空闲连接存活时间
config.setIdleMaxAgeInMinutes(10);
// 测试连接时间
config.setIdleConnectionTestPeriodInMinutes(10);
// 设置重新获取连接的次数。这个参数默认为5
config.setAcquireRetryAttempts(5);
// 重新获取连接的间隔时间
config.setAcquireRetryDelayInMs(3000);
boneCP = new BoneCP(config);
}
示例11: getBoneCPConfig
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private static BoneCPConfig getBoneCPConfig(NamingService ns) throws Exception {
BoneCPConfig config = new BoneCPConfig();
List<ServiceInstance<NodeType>> dbs = ns.list(NodeType.MDB, Predicates.<ServiceInstance<NodeType>>alwaysTrue());
if(dbs.isEmpty())
throw new Exception("unable to find any MDB node");
ServiceInstance<NodeType> mdb = dbs.get(0);
log.info("MDB service instance: {}", mdb);
String host = mdb.getAddress();
String db = mdb.getUriSpec().getParts().get(0).getValue();
int port = mdb.getPort();
String user = "uadmin";
String pass = "uadmin";
Integer min = 1;
Integer max = 5;
String jdbcUrl = "jdbc:postgresql://" + host + ":" + port + "/" + db;
config.setJdbcUrl(jdbcUrl);
config.setUsername(user);
config.setPassword(pass);
config.setMinConnectionsPerPartition(min);
config.setMaxConnectionsPerPartition(max);
config.setPartitionCount(1);
config.setLogStatementsEnabled(true);
return config;
}
示例12: BoneCPJdbcPool
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
public BoneCPJdbcPool(String url, String user, String pass, int min, int max) throws SQLException {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(url);
config.setUsername(user);
config.setPassword(pass);
config.setMinConnectionsPerPartition(min);
config.setMaxConnectionsPerPartition(max);
config.setPartitionCount(1);
config.setLogStatementsEnabled(true);
pool = new BoneCP(config); // setup the connection pool
}
示例13: pooled
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private static Connection pooled() throws SQLException {
// setup the connection pool
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:postgresql://localhost/taghvim"); // jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
config.setUsername("postgres");
config.setPassword("");
config.setMinConnectionsPerPartition(5);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
BoneCP connectionPool = new BoneCP(config); // setup the connection pool
return connectionPool.getConnection(); // fetch a connection
}
示例14: getBoneCPConfig
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
private static BoneCPConfig getBoneCPConfig(NamingService ns) throws Exception {
BoneCPConfig config = new BoneCPConfig();
List<ServiceInstance<NodeType>> dbs = ns.list(NodeType.MDB, Predicates.<ServiceInstance<NodeType>>alwaysTrue());
if(dbs.isEmpty())
throw new Exception("unable to find any MDB node");
ServiceInstance<NodeType> mdb = dbs.get(0);
log.info("MDB service instance: {}", mdb);
String host = mdb.getAddress();
String db = mdb.getUriSpec().getParts().get(0).getValue();
int port = mdb.getPort();
String user = "uadmin"; //properties.getProperty("mdb_user", "uadmin");
String pass = "uadmin"; //properties.getProperty("mdb_pass", "uadmin");
Integer min = 1; //Integer.parseInt(properties.getProperty("mdb_min", "1"));
Integer max = 5; //Integer.parseInt(properties.getProperty("mdb_max", "5"));
String jdbcUrl = "jdbc:postgresql://" + host + ":" + port + "/" + db;
log.info("jdbcUrl: {}", jdbcUrl);
config.setJdbcUrl(jdbcUrl);
config.setUsername(user);
config.setPassword(pass);
config.setMinConnectionsPerPartition(min);
config.setMaxConnectionsPerPartition(max);
config.setPartitionCount(1);
config.setLogStatementsEnabled(true);
return config;
}
示例15: setUp
import com.jolbox.bonecp.BoneCPConfig; //导入方法依赖的package包/类
@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);
}