本文整理汇总了Java中org.apache.commons.dbcp2.PoolableConnectionFactory.setMaxConnLifetimeMillis方法的典型用法代码示例。如果您正苦于以下问题:Java PoolableConnectionFactory.setMaxConnLifetimeMillis方法的具体用法?Java PoolableConnectionFactory.setMaxConnLifetimeMillis怎么用?Java PoolableConnectionFactory.setMaxConnLifetimeMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbcp2.PoolableConnectionFactory
的用法示例。
在下文中一共展示了PoolableConnectionFactory.setMaxConnLifetimeMillis方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
@Override
public void start() {
File databaseDir = new File(JiveGlobals.getHomeDirectory(), File.separator + "embedded-db");
// If the database doesn't exist, create it.
if (!databaseDir.exists()) {
databaseDir.mkdirs();
}
try {
serverURL = "jdbc:hsqldb:" + databaseDir.getCanonicalPath() + File.separator + "openfire";
}
catch (IOException ioe) {
Log.error("EmbeddedConnectionProvider: Error starting connection pool: ", ioe);
}
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, "sa", "");
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setMaxConnLifetimeMillis((long) (0.5 * JiveConstants.DAY));
final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMinIdle(3);
poolConfig.setMaxTotal(25);
final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
poolableConnectionFactory.setPool(connectionPool);
dataSource = new PoolingDataSource<>(connectionPool);
}
示例2: createPool
import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
public static DataSource createPool(ConnectionFactory connectionFactory, int isolation) {
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, null);
poolableConnectionFactory.setMaxConnLifetimeMillis(3000);
poolableConnectionFactory.setDefaultAutoCommit(false);
poolableConnectionFactory.setDefaultReadOnly(true);
poolableConnectionFactory
.setDefaultTransactionIsolation(isolation);
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
poolableConnectionFactory);
poolableConnectionFactory.setPool(connectionPool);
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
connectionPool);
return dataSource;
}
示例3: create
import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
static PoolableDataSource create(ConnectionFactory connectionFactory) {
// setup our pool config object
GenericObjectPoolConfig config = setupPoolConfig();
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(connectionFactory, null);
// Set max lifetime of a connection in milli-secs, after which it will
// always fail activation, passivation, and validation.
// Value of -1 means infinite life time. The default value
// defined in this class is 10 minutes.
long connTtlMillis = retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TTL, MAX_TTL_CONN_MS);
poolableConnectionFactory.setMaxConnLifetimeMillis(connTtlMillis);
if (LOG.isInfoEnabled()) {
LOG.info("Setting Time-To-Live interval for live connections (" +
connTtlMillis + ") milli-secs");
}
ObjectPool<PoolableConnection> connectionPool =
new GenericObjectPool<>(poolableConnectionFactory, config);
poolableConnectionFactory.setPool(connectionPool);
AthenzDataSource dataSource = new AthenzDataSource(connectionPool);
return dataSource;
}
示例4: start
import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
@Override
public void start() {
try {
Class.forName(driver);
} catch (final ClassNotFoundException e) {
throw new RuntimeException("Unable to find JDBC driver " + driver, e);
}
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, username, password);
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setValidationQuery(testSQL);
poolableConnectionFactory.setValidationQueryTimeout(testTimeout);
poolableConnectionFactory.setMaxConnLifetimeMillis((long) (connectionTimeout * JiveConstants.DAY));
final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setTestOnBorrow(testBeforeUse);
poolConfig.setTestOnReturn(testAfterUse);
poolConfig.setMinIdle(minConnections);
poolConfig.setMaxTotal(maxConnections);
poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
poolConfig.setSoftMinEvictableIdleTimeMillis(minIdleTime);
poolConfig.setMaxWaitMillis(maxWaitTime);
connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
poolableConnectionFactory.setPool(connectionPool);
dataSource = new PoolingDataSource<>(connectionPool);
}