List of usage examples for org.apache.commons.pool.impl GenericObjectPool setMinEvictableIdleTimeMillis
public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testEvictionSoftMinIdle() throws Exception { GenericObjectPool pool = null; class TimeTest extends BasePoolableObjectFactory { private final long createTime; public TimeTest() { createTime = System.currentTimeMillis(); }//w w w .java 2s . c o m public Object makeObject() throws Exception { return new TimeTest(); } public long getCreateTime() { return createTime; } } pool = new GenericObjectPool(new TimeTest()); pool.setMaxIdle(5); pool.setMaxActive(5); pool.setNumTestsPerEvictionRun(5); pool.setMinEvictableIdleTimeMillis(3000L); pool.setSoftMinEvictableIdleTimeMillis(1000L); pool.setMinIdle(2); Object[] active = new Object[5]; Long[] creationTime = new Long[5]; for (int i = 0; i < 5; i++) { active[i] = pool.borrowObject(); creationTime[i] = new Long(((TimeTest) active[i]).getCreateTime()); } for (int i = 0; i < 5; i++) { pool.returnObject(active[i]); } // Soft evict all but minIdle(2) Thread.sleep(1500L); pool.evict(); assertEquals("Idle count different than expected.", 2, pool.getNumIdle()); // Hard evict the rest. Thread.sleep(2000L); pool.evict(); assertEquals("Idle count different than expected.", 0, pool.getNumIdle()); }
From source file:org.apache.hadoop.hive.metastore.datasource.DbCPDataSourceProvider.java
@Override public DataSource create(Configuration hdpConfig) throws SQLException { LOG.debug("Creating dbcp connection pool for the MetaStore"); String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig); String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig); String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig); int maxPoolSize = hdpConfig.getInt(MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getVarname(), ((Long) MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getDefaultVal()).intValue()); long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L); int connectionMaxIlde = hdpConfig.getInt(CONNECTION_MAX_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MAX_IDLE); int connectionMinIlde = hdpConfig.getInt(CONNECTION_MIN_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MIN_IDLE); boolean testOnBorrow = hdpConfig.getBoolean(CONNECTION_TEST_BORROW_PROPERTY, GenericObjectPool.DEFAULT_TEST_ON_BORROW); long evictionTimeMillis = hdpConfig.getLong(CONNECTION_MIN_EVICT_MILLIS_PROPERTY, GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); boolean testWhileIdle = hdpConfig.getBoolean(CONNECTION_TEST_IDLEPROPERTY, GenericObjectPool.DEFAULT_TEST_WHILE_IDLE); long timeBetweenEvictionRuns = hdpConfig.getLong(CONNECTION_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); int numTestsPerEvictionRun = hdpConfig.getInt(CONNECTION_NUM_TESTS_PER_EVICTION_RUN, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN); boolean testOnReturn = hdpConfig.getBoolean(CONNECTION_TEST_ON_RETURN, GenericObjectPool.DEFAULT_TEST_ON_RETURN); long softMinEvictableIdleTimeMillis = hdpConfig.getLong(CONNECTION_SOFT_MIN_EVICTABLE_IDLE_TIME, GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); boolean lifo = hdpConfig.getBoolean(CONNECTION_LIFO, GenericObjectPool.DEFAULT_LIFO); GenericObjectPool objectPool = new GenericObjectPool(); objectPool.setMaxActive(maxPoolSize); objectPool.setMaxWait(connectionTimeout); objectPool.setMaxIdle(connectionMaxIlde); objectPool.setMinIdle(connectionMinIlde); objectPool.setTestOnBorrow(testOnBorrow); objectPool.setTestWhileIdle(testWhileIdle); objectPool.setMinEvictableIdleTimeMillis(evictionTimeMillis); objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns); objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun); objectPool.setTestOnReturn(testOnReturn); objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis); objectPool.setLifo(lifo);/*w w w . j a v a 2 s . com*/ ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, user, passwd); // This doesn't get used, but it's still necessary, see // https://git1-us-west.apache.org/repos/asf?p=commons-dbcp.git;a=blob;f=doc/ManualPoolingDataSourceExample.java; // h=f45af2b8481f030b27364e505984c0eef4f35cdb;hb=refs/heads/DBCP_1_5_x_BRANCH new PoolableConnectionFactory(connFactory, objectPool, null, null, false, true); return new PoolingDataSource(objectPool); }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public synchronized static void checkGlobalPoolingDataSource(String url, String user, String pass) { if (globalDbConPool != null) { return;/*from w w w. j a va2s .c o m*/ } else { LOG.error( "#################################################################### init master connetion pool"); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass); GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setMaxActive(poolActiveSize); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); connectionPool.setMaxWait(10000); connectionPool.setTestOnBorrow(true); connectionPool.setTestWhileIdle(true); connectionPool.setTimeBetweenEvictionRunsMillis(30000); connectionPool.setMinEvictableIdleTimeMillis(300000); connectionPool.setLifo(true); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); globalDbConPool = new PoolingDataSource(connectionPool); LOG.error( "#################################################################### init global connetion pool over"); } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public synchronized static PoolingDataSource getSegPoolingDataSource(String url, String user, String pass) { url = url.toLowerCase();//from w w w. j a v a 2s .co m PoolingDataSource pool = SegmentDbConPool.get(url); if (pool != null) { return pool; } else { LOG.debug( "#################################################################### init global connetion pool:" + url); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass); GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setMaxActive(poolActiveSize); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); connectionPool.setMaxWait(10000); connectionPool.setTestOnBorrow(true); connectionPool.setTestWhileIdle(true); connectionPool.setTimeBetweenEvictionRunsMillis(30000); connectionPool.setMinEvictableIdleTimeMillis(300000); connectionPool.setLifo(true); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); pool = new PoolingDataSource(connectionPool); SegmentDbConPool.put(url, pool); LOG.debug( "#################################################################### init global connetion pool:" + url + " over"); return pool; } }
From source file:org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.java
protected ObjectPool createConnectionPool(GenericObjectPool.Config config, AbandonedConfig ac) { final GenericObjectPool connectionPool; final boolean doRemoveAbandoned = ac != null && ac.getRemoveAbandoned(); if (doRemoveAbandoned) { connectionPool = new AbandonedObjectPool(null, ac); } else {/*from ww w.j av a2s . co m*/ connectionPool = new GenericObjectPool(); } connectionPool.setMaxActive(config.maxActive); connectionPool.setMaxIdle(config.maxIdle); connectionPool.setMinIdle(config.minIdle); connectionPool.setMaxWait(config.maxWait); connectionPool.setTestOnBorrow(config.testOnBorrow); connectionPool.setTestOnReturn(config.testOnReturn); connectionPool.setTimeBetweenEvictionRunsMillis(config.timeBetweenEvictionRunsMillis); connectionPool.setNumTestsPerEvictionRun(config.numTestsPerEvictionRun); connectionPool.setMinEvictableIdleTimeMillis(config.minEvictableIdleTimeMillis); connectionPool.setTestWhileIdle(config.testWhileIdle); return connectionPool; }
From source file:org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory.java
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException { SyslogPoolConfigIF poolConfig = null; try {//from ww w.j a v a 2 s.com poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig(); } catch (ClassCastException cce) { throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF"); } genericObjectPool.setMaxActive(poolConfig.getMaxActive()); genericObjectPool.setMaxIdle(poolConfig.getMaxIdle()); genericObjectPool.setMaxWait(poolConfig.getMaxWait()); genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis()); genericObjectPool.setMinIdle(poolConfig.getMinIdle()); genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun()); genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis()); genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow()); genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn()); genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle()); genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis()); genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction()); }
From source file:org.idevlab.rjc.ds.PoolableDataSource.java
private synchronized GenericObjectPool createPool() { if (closed) { throw new RedisException("Data source is closed"); }//from ww w . j a va 2s.co m if (connectionPool == null) { GenericObjectPool gop = new GenericObjectPool(); gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; createConnectionFactory(); try { for (int i = 0; i < initialSize; i++) { connectionPool.addObject(); } } catch (Exception e) { throw new RedisException("Error preloading the connection pool", e); } } return connectionPool; }
From source file:org.onexus.collection.store.mysql.internal.MysqlCollectionStore.java
protected DataSource newDataSource() { try {//from ww w.j ava 2 s .co m Class.forName(Driver.class.getName()); } catch (Exception e) { LOGGER.error("Exception: " + e.getMessage()); } // Config parameters int maxActive = 8; try { maxActive = Integer.valueOf(getPoolMaxActive().trim()).intValue(); } catch (Exception e) { LOGGER.error("Malformed config parameter 'poolMaxActive'"); } byte whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; try { if (getPoolWhenExhausted().trim().equalsIgnoreCase("FAIL")) { whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_FAIL; } if (getPoolWhenExhausted().trim().equalsIgnoreCase("GROW")) { whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_GROW; } } catch (Exception e) { LOGGER.error("Malformed config parameter 'poolWhenExhausted'"); } long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT; try { maxWait = Long.valueOf(getPoolMaxWait().trim()).longValue(); } catch (Exception e) { LOGGER.error("Malformed config parameter 'poolMaxWait'"); } // Initialize the DataSource with a connection pool ConnectionFactory connectionFactory = new MysqlConnectionFactory(); GenericObjectPool connectionPool = new GenericObjectPool(null, maxActive, whenExhausted, maxWait); connectionPool.setTestWhileIdle(true); connectionPool.setTimeBetweenEvictionRunsMillis(3600); connectionPool.setMinEvictableIdleTimeMillis(3600); @SuppressWarnings("unused") PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); poolableConnectionFactory.setValidationQuery("SELECT 1"); return new PoolingDataSource(connectionPool); }
From source file:org.openanzo.datasource.nodecentric.internal.NodeCentricDatasource.java
/** * Initialize a jdbc connection pool/* w w w . j a va2 s .c om*/ * * @param type * either rw or query pool * @param maxActive * maximum number of connections in pool * @param configuration * configuration properties used for creating database connections * @return connection pool * @throws AnzoException * {@link ExceptionConstants#RDB.DRIVER_NAME} if there was a problem loading class for database driver */ private GenericObjectPool initializeConnectionFactory(boolean write, int maxActive) throws AnzoException { // Will use in jndi // DataSource ds = (DataSource) ctx.lookup(RepositoryProperties.getDatabaseJndiName(properties)); try { Class.forName(configuration.getDriverClassName()); } catch (ClassNotFoundException e1) { throw new AnzoException(ExceptionConstants.RDB.DRIVER_NAME, e1, configuration.getDriverClassName()); } Properties props = new Properties(); props.put("user", configuration.getUser()); props.put("password", configuration.getPassword()); props.put("SetBigStringTryClob", "true"); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(configuration.getJdbcUrl(), props); GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setMaxActive(maxActive); connectionPool.setMaxIdle(Math.max(1, maxActive / 2)); connectionPool.setMinIdle(0); connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 10); connectionPool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 10); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); connectionPool.setMaxWait(GenericKeyedObjectPool.DEFAULT_MAX_WAIT); connectionPool.setTestOnBorrow(true); GenericKeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory(null, PS_CACHE_SIZE, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, GenericKeyedObjectPool.DEFAULT_MAX_WAIT, PS_CACHE_SIZE, PS_CACHE_SIZE, GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE); PoolableConnectionFactory pcf = new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, configuration.getValidationQuery(), false, true) { @Override public synchronized Object makeObject() throws Exception { Connection connection = (Connection) super.makeObject(); initializeConnection(connection); return connection; } }; if (configuration.getSupportsIsolation() && write) pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); else if (configuration.getSupportsIsolation() && !write) pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); return connectionPool; }
From source file:org.opencms.db.CmsDbPool.java
/** * Creates a JDBC DriverManager based DBCP connection pool.<p> * // w ww . j a va 2s .co m * @param config the configuration (opencms.properties) * @param key the key of the database pool in the configuration * @return String the URL to access the created DBCP pool * @throws Exception if the pool could not be initialized */ public static PoolingDriver createDriverManagerConnectionPool(CmsParameterConfiguration config, String key) throws Exception { // read the values of the pool configuration specified by the given key String jdbcDriver = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_JDBC_DRIVER); String jdbcUrl = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_JDBC_URL); String jdbcUrlParams = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_JDBC_URL_PARAMS); int maxActive = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_MAX_ACTIVE, 10); int maxWait = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_MAX_WAIT, 2000); int maxIdle = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_MAX_IDLE, 5); int minEvictableIdleTime = config .getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_MIN_EVICTABLE_IDLE_TIME, 1800000); int minIdle = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_MIN_IDLE, 0); int numTestsPerEvictionRun = config .getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_NUM_TESTS_PER_EVICTION_RUN, 3); int timeBetweenEvictionRuns = config .getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_TIME_BETWEEN_EVICTION_RUNS, 3600000); String testQuery = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_TEST_QUERY); String username = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_USERNAME); String password = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_PASSWORD); String poolUrl = config.get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_POOL_URL); String whenExhaustedActionValue = config .get(KEY_DATABASE_POOL + '.' + key + '.' + KEY_WHEN_EXHAUSTED_ACTION).trim(); byte whenExhaustedAction = 0; boolean testOnBorrow = Boolean .valueOf(config.getString(KEY_DATABASE_POOL + '.' + key + '.' + KEY_TEST_ON_BORROW, "false").trim()) .booleanValue(); boolean testWhileIdle = Boolean .valueOf( config.getString(KEY_DATABASE_POOL + '.' + key + '.' + KEY_TEST_WHILE_IDLE, "false").trim()) .booleanValue(); if ("block".equalsIgnoreCase(whenExhaustedActionValue)) { whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; } else if ("fail".equalsIgnoreCase(whenExhaustedActionValue)) { whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; } else if ("grow".equalsIgnoreCase(whenExhaustedActionValue)) { whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW; } else { whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION; } if ("".equals(testQuery)) { testQuery = null; } if (username == null) { username = ""; } if (password == null) { password = ""; } // read the values of the statement pool configuration specified by the given key boolean poolingStmts = Boolean.valueOf(config .getString(KEY_DATABASE_STATEMENTS + '.' + key + '.' + KEY_POOLING, CmsStringUtil.TRUE).trim()) .booleanValue(); int maxActiveStmts = config.getInteger(KEY_DATABASE_STATEMENTS + '.' + key + '.' + KEY_MAX_ACTIVE, 25); int maxWaitStmts = config.getInteger(KEY_DATABASE_STATEMENTS + '.' + key + '.' + KEY_MAX_WAIT, 250); int maxIdleStmts = config.getInteger(KEY_DATABASE_STATEMENTS + '.' + key + '.' + KEY_MAX_IDLE, 15); String whenStmtsExhaustedActionValue = config .get(KEY_DATABASE_STATEMENTS + '.' + key + '.' + KEY_WHEN_EXHAUSTED_ACTION); byte whenStmtsExhaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW; if (whenStmtsExhaustedActionValue != null) { whenStmtsExhaustedActionValue = whenStmtsExhaustedActionValue.trim(); whenStmtsExhaustedAction = ("block".equalsIgnoreCase(whenStmtsExhaustedActionValue)) ? GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK : ("fail".equalsIgnoreCase(whenStmtsExhaustedActionValue)) ? GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL : GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW; } int connectionAttempts = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_CONNECT_ATTEMTS, 10); int connetionsWait = config.getInteger(KEY_DATABASE_POOL + '.' + key + '.' + KEY_CONNECT_WAITS, 5000); // create an instance of the JDBC driver Class.forName(jdbcDriver).newInstance(); // initialize a keyed object pool to store connections GenericObjectPool connectionPool = new GenericObjectPool(null); /* Abandoned pool configuration: * * In case the systems encounters "pool exhaustion" (runs out of connections), * comment the above line with "new GenericObjectPool(null)" and uncomment the * 5 lines below. This will generate an "abandoned pool" configuration that logs * abandoned connections to the System.out. Unfortunatly this code is deprecated, * so to avoid code warnings it's also disabled here. * Tested with commons-pool v 1.2. */ // AbandonedConfig abandonedConfig = new AbandonedConfig(); // abandonedConfig.setLogAbandoned(true); // abandonedConfig.setRemoveAbandoned(true); // abandonedConfig.setRemoveAbandonedTimeout(5); // GenericObjectPool connectionPool = new AbandonedObjectPool(null, abandonedConfig); // initialize an object pool to store connections connectionPool.setMaxActive(maxActive); connectionPool.setMaxIdle(maxIdle); connectionPool.setMinIdle(minIdle); connectionPool.setMaxWait(maxWait); connectionPool.setWhenExhaustedAction(whenExhaustedAction); if (testQuery != null) { connectionPool.setTestOnBorrow(testOnBorrow); connectionPool.setTestWhileIdle(testWhileIdle); connectionPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns); connectionPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun); connectionPool.setMinEvictableIdleTimeMillis(minEvictableIdleTime); } // initialize a connection factory to make the DriverManager taking connections from the pool if (jdbcUrlParams != null) { jdbcUrl += jdbcUrlParams; } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(jdbcUrl, username, password); // Set up statement pool, if desired GenericKeyedObjectPoolFactory statementFactory = null; if (poolingStmts) { statementFactory = new GenericKeyedObjectPoolFactory(null, maxActiveStmts, whenStmtsExhaustedAction, maxWaitStmts, maxIdleStmts); } // initialize a factory to obtain pooled connections and prepared statements new PoolableConnectionFactory(connectionFactory, connectionPool, statementFactory, testQuery, false, true); // initialize a new pooling driver using the pool PoolingDriver driver = new PoolingDriver(); driver.registerPool(poolUrl, connectionPool); Connection con = null; boolean connect = false; int connectionTests = 0; // try to connect once to the database to ensure it can be connected to at all // if the conection cannot be established, multiple attempts will be done to connect // just in cast the database was not fast enough to start before OpenCms was started do { try { // try to connect con = connectionFactory.createConnection(); connect = true; } catch (Exception e) { // connection failed, increase attempts, sleept for some seconds and log a message connectionTests++; if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_WAIT_FOR_DB_4, new Object[] { poolUrl, jdbcUrl, new Integer(connectionTests), new Integer(connetionsWait) })); } Thread.sleep(connetionsWait); } finally { if (con != null) { con.close(); } } } while (!connect && (connectionTests < connectionAttempts)); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_JDBC_POOL_2, poolUrl, jdbcUrl)); } return driver; }