List of usage examples for org.apache.commons.pool.impl GenericObjectPool setMinEvictableIdleTimeMillis
public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
From source file:org.springframework.aop.target.CommonsPoolTargetSource.java
/** * Subclasses can override this if they want to return a specific Commons pool. * They should apply any configuration properties to the pool here. * <p>Default is a GenericObjectPool instance with the given pool size. * @return an empty Commons {@code ObjectPool}. * @see org.apache.commons.pool.impl.GenericObjectPool * @see #setMaxSize/*from w w w .j a v a 2s . c o m*/ */ protected ObjectPool createObjectPool() { GenericObjectPool gop = new GenericObjectPool(this); gop.setMaxActive(getMaxSize()); gop.setMaxIdle(getMaxIdle()); gop.setMinIdle(getMinIdle()); gop.setMaxWait(getMaxWait()); gop.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); gop.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); gop.setWhenExhaustedAction(getWhenExhaustedAction()); return gop; }
From source file:org.springframework.jms.listener.serversession.CommonsPoolServerSessionFactory.java
/** * Subclasses can override this if they want to return a specific Commons pool. * They should apply any configuration properties to the pool here. * <p>Default is a GenericObjectPool instance with the given pool size. * @param sessionManager the session manager to use for * creating and executing new listener sessions * @return an empty Commons <code>ObjectPool</code>. * @see org.apache.commons.pool.impl.GenericObjectPool * @see #setMaxSize//www.ja v a 2 s . com */ protected ObjectPool createObjectPool(ListenerSessionManager sessionManager) { GenericObjectPool pool = new GenericObjectPool(createPoolableObjectFactory(sessionManager)); pool.setMaxActive(getMaxSize()); pool.setMaxIdle(getMaxIdle()); pool.setMinIdle(getMinIdle()); pool.setMaxWait(getMaxWait()); pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); return pool; }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Configures the database connection pool and sets the pool configuration. * /*from ww w . jav a 2 s .c om*/ * @param connectionPool * The ObjectPool * @param connectURI * The url specifying the database to which it * connects using JDBC * @param pUserId * The user id attribute * @param pPassword * The password attribute * * @throws java.lang.Exception * Throws an SQL exception that provides * information on a database access error * or other errors * * @todo Make the pool access dynamic (use the dynamic class loader?) * so that the application will compile/run without the Apache * commons library. */ private void configurePool(GenericObjectPool connectionPool, String connectURI, String pUserId, String pPassword) throws Exception { String lowerCaseConnectURI; String validationQuery; lowerCaseConnectURI = connectURI.toLowerCase(); validationQuery = null; if (lowerCaseConnectURI.startsWith("jdbc:sybase")) { validationQuery = "select getdate()"; } else if (lowerCaseConnectURI.startsWith("jdbc:mysql")) { validationQuery = "select 1"; } else if (lowerCaseConnectURI.startsWith("jdbc:oracle")) { validationQuery = "select sysdate from dual"; } else if (lowerCaseConnectURI.startsWith("jdbc:mssql")) { validationQuery = "select 1"; } // Pool settings - someday a dialog and persistence should be // added to put these under user control connectionPool.setMaxActive(1); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); connectionPool.setMaxWait(CONN_POOL_MAX_WAIT_MS); connectionPool.setMaxIdle(CONN_POOL_MAX_IDLE_CONNECTIONS); connectionPool.setTimeBetweenEvictionRunsMillis(CONN_POOL_TIME_BETWEEN_EVICT_RUNS_MS); connectionPool.setNumTestsPerEvictionRun(CONN_POOL_NUM_TESTS_PER_EVICT_RUN); connectionPool.setMinEvictableIdleTimeMillis(CONN_POOL_EVICT_IDLE_TIME_MS); final DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, pUserId, pPassword); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); if (validationQuery != null) { connectionPool.setTestOnBorrow(true); connectionPool.setTestWhileIdle(true); poolableConnectionFactory.setValidationQuery(validationQuery); } }