Example usage for org.apache.commons.pool.impl GenericObjectPool setMinIdle

List of usage examples for org.apache.commons.pool.impl GenericObjectPool setMinIdle

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool setMinIdle.

Prototype

public synchronized void setMinIdle(int minIdle) 

Source Link

Document

Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects.

Usage

From source file:org.plasma.sdo.jdbc.connect.RDBConnectionManager.java

/**
 * //  w  w  w . jav  a 2 s .c  o  m
 * @param connectURI
 *            - JDBC Connection URI
 * @param username
 *            - JDBC Connection username
 * @param password
 *            - JDBC Connection password
 * @param minIdle
 *            - Minimum number of idel connection in the connection pool
 * @param maxActive
 *            - Connection Pool Maximum Capacity (Size)
 * @throws Exception
 */
private static DataSource setup(String connectURI, String username, String password, int minIdle, int maxActive,
        Map<String, String> props) throws Exception {
    //
    // Create an ObjectPool that serves as the
    // actual pool of connections.
    //
    // Use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    GenericObjectPool.Config config = createGenericObjectPoolConfig(props);

    GenericObjectPool connectionPool = new GenericObjectPool(null, config);

    connectionPool.setMinIdle(minIdle);
    connectionPool.setMaxActive(maxActive);

    RDBConnectionManager._pool = connectionPool;
    // We keep it for two reasons
    // #1 We need it for statistics/debugging
    // #2 PoolingDataSource does not have getPool()
    // method, for some obscure, weird reason.

    //
    // Create a ConnectionFactory that the
    // pool will use to create Connections.
    // Use the DriverManagerConnectionFactory,
    // using the connect string from configuration
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username, password);

    //
    // Create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, true);

    String value = getValue(DBCP_VALIDATIONQUERY, props);
    if (value != null) {
        try {
            poolableConnectionFactory.setValidationQuery(value);
        } catch (Exception e) {
            throw new JDBCServiceException(e);
        }
    }

    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
}

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//w  w  w  .j av a  2  s  .  c  om
 */
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/*from   ww w. ja  va  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;
}