本文整理匯總了Java中org.apache.commons.pool2.impl.GenericObjectPool.setTestOnBorrow方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericObjectPool.setTestOnBorrow方法的具體用法?Java GenericObjectPool.setTestOnBorrow怎麽用?Java GenericObjectPool.setTestOnBorrow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.pool2.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.setTestOnBorrow方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createPool
import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
private ObjectPool<PoolableConnection> createPool(String connectionString) {
// A ConnectionFactory that the pool will use to create Connections.
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(connectionString, null);
// PoolableConnectionFactory wraps the real Connections with the
// classes that implement the pooling functionality.
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setValidationQuery("SELECT 1");
// Actual pool of connections.
GenericObjectPool<PoolableConnection> connectionPool =
new GenericObjectPool<>(poolableConnectionFactory);
int connMax = getConfig()
.getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
connectionPool.setMaxTotal(connMax);
connectionPool.setTestOnBorrow(true);
// Set the factory's pool property to the owning pool.
poolableConnectionFactory.setPool(connectionPool);
return connectionPool;
}
示例2: initializeThriftConnectionPool
import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
/**
* Initialize a new thrift client connection pool.
*/
private void initializeThriftConnectionPool() {
int thriftClientPoolSize = AndesConfigurationManager
.readValue(AndesConfiguration.PERFORMANCE_TUNING_THRIFT_CLIENT_POOL_SIZE);
GenericObjectPool<SlotManagementService.Client> thriftConnectionPool = new GenericObjectPool<>(
thriftClientFactory);
thriftConnectionPool.setMaxTotal(thriftClientPoolSize);
thriftConnectionPool.setTestOnBorrow(true);
if (socketTimeout > 0) {
thriftConnectionPool.setTimeBetweenEvictionRunsMillis(socketTimeout / 2);
thriftConnectionPool.setMinEvictableIdleTimeMillis(socketTimeout);
}
thriftClientPool = thriftConnectionPool;
}
示例3: 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;
}
示例4: doInitialize
import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
@Override
protected void doInitialize() throws Exception {
this.factory = new NettyClientFactory(target);
this.factory.start();
GenericObjectPool<NettyClient> genericObjectPool = new GenericObjectPool<>(factory, config);
genericObjectPool.setTestOnBorrow(true);
genericObjectPool.setTestOnCreate(true);
this.objectPool = genericObjectPool;
}
示例5: 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;
}
示例6: testNullValidationQuery
import org.apache.commons.pool2.impl.GenericObjectPool; //導入方法依賴的package包/類
/**
* JIRA: DBCP-442
*/
@Test
public void testNullValidationQuery() throws Exception {
final CPDSConnectionFactory factory =
new CPDSConnectionFactory(cpds, null, -1, false, "username", "password");
final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory);
factory.setPool(pool);
pool.setTestOnBorrow(true);
final PooledConnection pcon = pool.borrowObject().getPooledConnection();
final Connection con = pcon.getConnection();
con.close();
}
示例7: 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.");
}
}
示例8: 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);
}
}