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

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

Introduction

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

Prototype

byte WHEN_EXHAUSTED_BLOCK

To view the source code for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_BLOCK.

Click Source Link

Document

A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should block until a new object is available, or the #getMaxWait maximum wait time has been reached.

Usage

From source file:org.yosemite.jcsadra.impl.SimpleCassandraClientPool.java

public static byte getObjectPoolExhaustedAction(ExhaustedAction exhaustedAction) {
    switch (exhaustedAction) {
    case WHEN_EXHAUSTED_FAIL:
        return GenericObjectPool.WHEN_EXHAUSTED_FAIL;
    case WHEN_EXHAUSTED_BLOCK:
        return GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    case WHEN_EXHAUSTED_GROW:
        return GenericObjectPool.WHEN_EXHAUSTED_GROW;
    default:/* w  ww.ja v a 2s  .c om*/
        return GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    }
}

From source file:scriberlog.Scribelog2.java

private Scribelog2(String host, int port) {

    Config poolconf = new Config();
    poolconf.maxActive = 80;// w w  w.  ja  v  a 2 s .c o m
    poolconf.minIdle = 5;
    poolconf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    poolconf.testOnBorrow = true;
    poolconf.testWhileIdle = true;
    poolconf.numTestsPerEvictionRun = 10;
    poolconf.maxWait = 3000;

    _pool = new ScribeClientPool<ScribeService.Client>(
            new ScribeClientPool.ClientFactory<ScribeService.Client>() {
                @Override
                public ScribeService.Client make(TProtocol tProtocol) {
                    return new ScribeService.Client(tProtocol);
                }
            }, poolconf, host, port);
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Configures the database connection pool and sets the pool configuration.
 * /*from ww  w . jav a2 s  .co m*/
 * @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);
    }
}