本文整理汇总了Java中org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig.setTestOnBorrow方法的典型用法代码示例。如果您正苦于以下问题:Java GenericKeyedObjectPoolConfig.setTestOnBorrow方法的具体用法?Java GenericKeyedObjectPoolConfig.setTestOnBorrow怎么用?Java GenericKeyedObjectPoolConfig.setTestOnBorrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig
的用法示例。
在下文中一共展示了GenericKeyedObjectPoolConfig.setTestOnBorrow方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() throws InterruptedException {
this.appKey = "proxytest" + NumUtil.nextNum();
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(this.appKey, "127.0.0.1", NumUtil.nextPort());
ZkRegistry zkRegistry = serviceFactoryTest.getZkRegistry();
serverArgs.setRegistrys(ImmutableList.of(zkRegistry));
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例2: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() throws InterruptedException {
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(appKey, "127.0.0.1", port);
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例3: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() {
this.port = RandomUtils.nextInt(10000, 20000);
new DemoServer().startDaemon(this.port);
config = new GenericKeyedObjectPoolConfig();
config.setMaxTotal(MAX_CONN);
config.setMaxTotalPerKey(MAX_CONN);
config.setMaxIdlePerKey(MAX_CONN);
config.setMinIdlePerKey(MIN_CONN);
config.setTestOnBorrow(true);
config.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
config.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
config.setJmxEnabled(false);
}
示例4: registerPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
private void registerPool(final String username, final String password)
throws NamingException, SQLException {
final ConnectionPoolDataSource cpds = testCPDS(username, password);
// Create an object pool to contain our PooledConnections
factory = new KeyedCPDSConnectionFactory(cpds, getValidationQuery(),
getValidationQueryTimeout(), isRollbackAfterValidation());
factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
final GenericKeyedObjectPoolConfig config =
new GenericKeyedObjectPoolConfig();
config.setBlockWhenExhausted(getDefaultBlockWhenExhausted());
config.setEvictionPolicyClassName(getDefaultEvictionPolicyClassName());
config.setLifo(getDefaultLifo());
config.setMaxIdlePerKey(getDefaultMaxIdle());
config.setMaxTotal(getMaxTotal());
config.setMaxTotalPerKey(getDefaultMaxTotal());
config.setMaxWaitMillis(getDefaultMaxWaitMillis());
config.setMinEvictableIdleTimeMillis(
getDefaultMinEvictableIdleTimeMillis());
config.setMinIdlePerKey(getDefaultMinIdle());
config.setNumTestsPerEvictionRun(getDefaultNumTestsPerEvictionRun());
config.setSoftMinEvictableIdleTimeMillis(
getDefaultSoftMinEvictableIdleTimeMillis());
config.setTestOnCreate(getDefaultTestOnCreate());
config.setTestOnBorrow(getDefaultTestOnBorrow());
config.setTestOnReturn(getDefaultTestOnReturn());
config.setTestWhileIdle(getDefaultTestWhileIdle());
config.setTimeBetweenEvictionRunsMillis(
getDefaultTimeBetweenEvictionRunsMillis());
final KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> tmpPool =
new GenericKeyedObjectPool<>(factory, config);
factory.setPool(tmpPool);
pool = tmpPool;
}
示例5: getConfig
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
private GenericKeyedObjectPoolConfig getConfig(PoolConfig poolConfig) {
GenericKeyedObjectPoolConfig objectPoolConfig = new GenericKeyedObjectPoolConfig();
objectPoolConfig.setMaxTotalPerKey(poolConfig.getMaxTotalPerKey());
objectPoolConfig.setMaxTotal(poolConfig.getMaxTotal());
objectPoolConfig.setMaxIdlePerKey(poolConfig.getMaxIdlePerKey());
objectPoolConfig.setMinIdlePerKey(poolConfig.getMinIdlePerKey());
objectPoolConfig.setTestWhileIdle(poolConfig.isTestWhileIdle());
objectPoolConfig.setTestOnReturn(poolConfig.isTestOnReturn());
objectPoolConfig.setTestOnCreate(poolConfig.isTestOnCreate());
objectPoolConfig.setTestOnBorrow(poolConfig.isTestOnBorrow());
objectPoolConfig.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
objectPoolConfig.setEvictionPolicyClassName(poolConfig.getEvictionPolicyClassName());
objectPoolConfig.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
objectPoolConfig.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
objectPoolConfig.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
objectPoolConfig.setJmxEnabled(poolConfig.isJmxEnabled());
objectPoolConfig.setJmxNameBase(poolConfig.getJmxNameBase());
objectPoolConfig.setJmxNamePrefix(poolConfig.getJmxNamePrefix());
objectPoolConfig.setMaxWaitMillis(poolConfig.getMaxWaitMillis());
objectPoolConfig.setFairness(poolConfig.isFairness());
objectPoolConfig.setBlockWhenExhausted(poolConfig.isBlockWhenExhausted());
objectPoolConfig.setLifo(poolConfig.isLifo());
return objectPoolConfig;
}
示例6: ThriftConnectionPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
public ThriftConnectionPool(Class<T> cls, ThriftPoolConfig cfg,ThriftConnectionFactory connectionFactory) {
this.clientClass = cls;
this.cfg = cfg;
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setLifo(cfg.getBoolean("thrift.pool.lifo", false));
poolConfig.setMaxTotal(cfg.getInt("thrift.pool.maxActive", 10));
poolConfig.setMaxIdlePerKey(cfg.getInt("thrift.pool.maxIdlePerKey", 3));
poolConfig.setMinIdlePerKey(cfg.getInt("thrift.pool.minIdlePerKey", 0));
poolConfig.setMaxTotalPerKey(cfg.getInt("thrift.pool.maxTotalPerKey", 10));
/**
set the maximum amount of time (in milliseconds) the
<code>borrowObject()</code> method should block before throwing an
exception when the pool is exhausted and {@link #getBlockWhenExhausted} is true.
When less than 0, the <code>borrowObject()</code> method may block indefinitely.
*/
poolConfig.setMaxWaitMillis(cfg.getInt("thrift.pool.maxWait",20 * 1000));
/**
Sets whether to block when the <code>borrowObject()</code> method is
invoked when the pool is exhausted (the maximum number of "active"
objects has been reached).
*/
poolConfig.setBlockWhenExhausted(true);
/**为了提升性能 关闭testOnBorrow**/
poolConfig.setTestOnBorrow(false);
poolConfig.setTestWhileIdle(true);
this.loop = cfg.getBoolean("thrift.pool.get.loop",false);
// 开启一个线程执行扫描检测connection
poolConfig.setTimeBetweenEvictionRunsMillis(cfg.getInt("thrift.pool.timeBetweenEvictionRunsMillis",3*60*1000));
poolConfig.setMinEvictableIdleTimeMillis(cfg.getInt("thrift.pool.minEvictableIdleTimeMillis",5*60*1000));
poolConfig.setNumTestsPerEvictionRun(cfg.getInt("thrift.pool.numTestsPerEvictionRun",3));
this.factory = connectionFactory;
this.factory.setPool(this);
mPool = new GenericKeyedObjectPool<>(factory, poolConfig);
}