本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPool.setMaxWaitMillis方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.setMaxWaitMillis方法的具体用法?Java GenericObjectPool.setMaxWaitMillis怎么用?Java GenericObjectPool.setMaxWaitMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.setMaxWaitMillis方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnectionPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* Creates a connection pool for this datasource. This method only exists
* so subclasses can replace the implementation class.
*
* This implementation configures all pool properties other than
* timeBetweenEvictionRunsMillis. Setting that property is deferred to
* {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
* to a positive value causes {@link GenericObjectPool}'s eviction timer
* to be started.
*/
protected void createConnectionPool(final PoolableConnectionFactory factory) {
// Create an object pool to contain our active connections
final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
updateJmxName(config);
config.setJmxEnabled(registeredJmxObjectName != null); // Disable JMX on the underlying pool if the DS is not registered.
final GenericObjectPool<PoolableConnection> gop = createObjectPool(factory, config, abandonedConfig);
gop.setMaxTotal(maxTotal);
gop.setMaxIdle(maxIdle);
gop.setMinIdle(minIdle);
gop.setMaxWaitMillis(maxWaitMillis);
gop.setTestOnCreate(testOnCreate);
gop.setTestOnBorrow(testOnBorrow);
gop.setTestOnReturn(testOnReturn);
gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
gop.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
gop.setTestWhileIdle(testWhileIdle);
gop.setLifo(lifo);
gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
gop.setEvictionPolicyClassName(evictionPolicyClassName);
factory.setPool(gop);
connectionPool = gop;
}
示例2: testFixFactoryConfig
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* DBCP-412
* Verify that omitting factory.setPool(pool) when setting up PDS does not
* result in NPE.
*/
@Test
public void testFixFactoryConfig() throws Exception {
final Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "password");
final PoolableConnectionFactory f =
new PoolableConnectionFactory(
new DriverConnectionFactory(new TesterDriver(),
"jdbc:apache:commons:testdriver", props),
null);
f.setValidationQuery("SELECT DUMMY FROM DUAL");
f.setDefaultReadOnly(Boolean.TRUE);
f.setDefaultAutoCommit(Boolean.TRUE);
final GenericObjectPool<PoolableConnection> p = new GenericObjectPool<>(f);
p.setMaxTotal(getMaxTotal());
p.setMaxWaitMillis(getMaxWaitMillis());
ds = new PoolingDataSource<>(p);
assertTrue(f.getPool().equals(p));
ds.getConnection();
}
示例3: createProcessPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private GenericObjectPool<PhantomJSProcess> createProcessPool(JRPropertiesUtil properties)
{
ProcessFactory processFactory = new ProcessFactory(this, properties);
GenericObjectPool<PhantomJSProcess> pool = new GenericObjectPool<>(processFactory);
pool.setLifo(true);
int maxProcessCount = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_MAX_PROCESS_COUNT,
PhantomJS.DEFAULT_PHANTOMJS_MAX_PROCESS_COUNT);
pool.setMaxTotal(maxProcessCount);
pool.setMaxIdle(maxProcessCount);
int borrowTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_POOL_BORROW_TIMEOUT,
PhantomJS.DEFAULT_PHANTOMJS_POOL_BORROW_TIMEOUT);
pool.setMaxWaitMillis(borrowTimeout);
int idleTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_IDLE_TIMEOUT,
PhantomJS.DEFAULT_PHANTOMJS_IDLE_TIMEOUT);
pool.setMinEvictableIdleTimeMillis(idleTimeout);
pool.setTimeBetweenEvictionRunsMillis(idlePingInterval);
pool.setTestWhileIdle(true);
pool.setNumTestsPerEvictionRun(Integer.MAX_VALUE);
pool.setSwallowedExceptionListener(new SwallowedExceptionListener()
{
@Override
public void onSwallowException(Exception e)
{
if (log.isDebugEnabled())
{
log.debug("Pool exception", e);
}
}
});
return pool;
}
示例4: init
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
synchronized public ThriftClientPool<T, I> init() {
if (thriftClientPool == null) {
if (tprotocolFactory == null) {
throw new IllegalStateException("No ITProtocolFactory instance found!");
}
if (retryPolicy == null) {
retryPolicy = RetryPolicy.DEFAULT;
}
ThriftClientFactory factory = new ThriftClientFactory();
GenericObjectPool<I> pool = new GenericObjectPool<I>(factory);
pool.setBlockWhenExhausted(true);
pool.setTestOnReturn(false);
int maxActive = poolConfig != null ? poolConfig.getMaxActive()
: PoolConfig.DEFAULT_MAX_ACTIVE;
long maxWaitTime = poolConfig != null ? poolConfig.getMaxWaitTime()
: PoolConfig.DEFAULT_MAX_WAIT_TIME;
int maxIdle = poolConfig != null ? poolConfig.getMaxIdle()
: PoolConfig.DEFAULT_MAX_IDLE;
int minIdle = poolConfig != null ? poolConfig.getMinIdle()
: PoolConfig.DEFAULT_MIN_IDLE;
pool.setMaxTotal(maxActive);
pool.setMaxIdle(maxIdle);
pool.setMinIdle(minIdle);
pool.setMaxWaitMillis(maxWaitTime);
pool.setTestOnBorrow(poolConfig != null ? poolConfig.isTestOnBorrow() : false);
pool.setTestOnCreate(poolConfig != null ? poolConfig.isTestOnCreate() : false);
pool.setTestWhileIdle(poolConfig != null ? poolConfig.isTestWhileIdle() : false);
pool.setTimeBetweenEvictionRunsMillis(10000);
this.thriftClientPool = pool;
}
return this;
}
示例5: testClose
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void testClose() throws Exception {
final Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "password");
final PoolableConnectionFactory f =
new PoolableConnectionFactory(
new DriverConnectionFactory(new TesterDriver(),
"jdbc:apache:commons:testdriver", props),
null);
f.setValidationQuery("SELECT DUMMY FROM DUAL");
f.setDefaultReadOnly(Boolean.TRUE);
f.setDefaultAutoCommit(Boolean.TRUE);
final GenericObjectPool<PoolableConnection> p = new GenericObjectPool<>(f);
p.setMaxTotal(getMaxTotal());
p.setMaxWaitMillis(getMaxWaitMillis());
try ( PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(p) ) {
final Connection connection = dataSource.getConnection();
assertNotNull(connection);
connection.close();
}
assertTrue(p.isClosed());
assertEquals(0, p.getNumIdle());
assertEquals(0, p.getNumActive());
}
示例6: createDbcp
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private void createDbcp(DbcpConfig conf)
{
if (!dataSources.containsKey(conf.name))
{
try
{
Class.forName(conf.driverClassName);
DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory(conf.jdbc,conf.user,conf.password);
PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf,null);
pcf.setValidationQuery(conf.validationQuery);
//, pool, null, conf.validationQuery, false, true,abandondedConfig);
logger.info("Creating pool "+conf.toString());
// create a generic pool
GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pcf);
pool.setMaxTotal(conf.maxTotal);
pool.setMaxIdle(conf.maxIdle);
pool.setMinIdle(conf.minIdle);
pool.setMaxWaitMillis(conf.maxWait);
pool.setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
pool.setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
pool.setTestWhileIdle(conf.testWhileIdle);
pool.setTestOnBorrow(conf.testOnBorrow);
AbandonedConfig abandonedConfig = new AbandonedConfig();
abandonedConfig.setRemoveAbandonedOnMaintenance(conf.removeAbanadoned);
abandonedConfig.setRemoveAbandonedTimeout(conf.removeAbandonedTimeout);
abandonedConfig.setLogAbandoned(conf.logAbandonded);
pool.setAbandonedConfig(abandonedConfig);
pcf.setPool(pool);
DataSource ds = new PoolingDataSource(pool);
dataSources.put(conf.name, ds);
} catch (ClassNotFoundException e) {
logger.error("Failed to create datasource for "+conf.name+ " with class "+conf.driverClassName);
}
}
else
{
logger.error("Pool "+conf.name+" already exists. Can't change existing datasource at present.");
}
}
示例7: registerPool
import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private synchronized void registerPool(final String username, final String password)
throws NamingException, SQLException {
final ConnectionPoolDataSource cpds = testCPDS(username, password);
// Set up the factory we will use (passing the pool associates
// the factory with the pool, so we do not have to do so
// explicitly)
final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds,
getValidationQuery(), getValidationQueryTimeout(),
isRollbackAfterValidation(), username, password);
factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
// Create an object pool to contain our PooledConnections
final GenericObjectPool<PooledConnectionAndInfo> pool =
new GenericObjectPool<>(factory);
factory.setPool(pool);
pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(username));
pool.setEvictionPolicyClassName(
getPerUserEvictionPolicyClassName(username));
pool.setLifo(getPerUserLifo(username));
pool.setMaxIdle(getPerUserMaxIdle(username));
pool.setMaxTotal(getPerUserMaxTotal(username));
pool.setMaxWaitMillis(getPerUserMaxWaitMillis(username));
pool.setMinEvictableIdleTimeMillis(
getPerUserMinEvictableIdleTimeMillis(username));
pool.setMinIdle(getPerUserMinIdle(username));
pool.setNumTestsPerEvictionRun(
getPerUserNumTestsPerEvictionRun(username));
pool.setSoftMinEvictableIdleTimeMillis(
getPerUserSoftMinEvictableIdleTimeMillis(username));
pool.setTestOnCreate(getPerUserTestOnCreate(username));
pool.setTestOnBorrow(getPerUserTestOnBorrow(username));
pool.setTestOnReturn(getPerUserTestOnReturn(username));
pool.setTestWhileIdle(getPerUserTestWhileIdle(username));
pool.setTimeBetweenEvictionRunsMillis(
getPerUserTimeBetweenEvictionRunsMillis(username));
pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
final Object old = managers.put(getPoolKey(username), factory);
if (old != null) {
throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
}
}