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

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

Introduction

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

Prototype

long DEFAULT_MAX_WAIT

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

Click Source Link

Document

The default maximum amount of time (in milliseconds) the #borrowObject method should block before throwing an exception when the pool is exhausted and the #getWhenExhaustedAction "when exhausted" action is #WHEN_EXHAUSTED_BLOCK .

Usage

From source file:org.onexus.collection.store.mysql.internal.MysqlCollectionStore.java

protected DataSource newDataSource() {

    try {/*  w w  w. j a  v a 2 s  .c  om*/
        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.onexus.website.api.widgets.tags.tagstore.TagStoreManager.java

public void init() {
    LOGGER.debug("Connecting to '{}' as '{}'.", database, username);

    Driver.load();//from  w w w.j a va 2  s.c o m

    // Initialize the DataSource with a connection pool
    ConnectionFactory connectionFactory = new H2ConnectionFactory();
    ObjectPool connectionPool = new GenericObjectPool(null, GenericObjectPool.DEFAULT_MAX_ACTIVE,
            GenericObjectPool.WHEN_EXHAUSTED_GROW, GenericObjectPool.DEFAULT_MAX_WAIT);
    @SuppressWarnings("unused")
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, true);
    dataSource = new PoolingDataSource(connectionPool);

    this.tagStores = Collections.synchronizedMap(new HashMap<String, TagStore>());

}

From source file:org.springframework.boot.autoconfigure.jdbc.CommonsDataSourceConfigurationTests.java

@Test
public void testDataSourceDefaultsPreserved() throws Exception {
    this.context.register(CommonsDataSourceConfiguration.class);
    this.context.refresh();
    BasicDataSource ds = this.context.getBean(BasicDataSource.class);
    assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            ds.getTimeBetweenEvictionRunsMillis());
    assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, ds.getMinEvictableIdleTimeMillis());
    assertEquals(GenericObjectPool.DEFAULT_MAX_WAIT, ds.getMaxWait());
}

From source file:org.springframework.boot.autoconfigure.jdbc.CommonsDbcpDataSourceConfigurationTests.java

@Test
public void testDataSourceDefaultsPreserved() throws Exception {
    this.context.register(CommonsDbcpDataSourceConfiguration.class);
    this.context.refresh();
    BasicDataSource ds = this.context.getBean(BasicDataSource.class);
    assertThat(ds.getTimeBetweenEvictionRunsMillis())
            .isEqualTo(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    assertThat(ds.getMinEvictableIdleTimeMillis())
            .isEqualTo(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    assertThat(ds.getMaxWait()).isEqualTo(GenericObjectPool.DEFAULT_MAX_WAIT);
}