Example usage for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

Introduction

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

Prototype

public GenericObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config) 

Source Link

Document

Create a new GenericObjectPool using a specific configuration.

Usage

From source file:org.zbus.pool.impl.CommonsPool2.java

public CommonsPool2(ObjectFactory<T> supportFactory, PoolConfig config) {
    Commons2PoolFactory factory = new Commons2PoolFactory(supportFactory);
    GenericObjectPoolConfig poolConfig = null;
    if (config.getSupport() instanceof GenericObjectPoolConfig) {
        poolConfig = (GenericObjectPoolConfig) config.getSupport();
    } else {/* w  w  w .j  a v a 2  s  . c o m*/
        poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxTotal(config.getMaxTotal());
        poolConfig.setMaxIdle(config.getMaxIdle());
        poolConfig.setMinIdle(config.getMinIdle());
        poolConfig.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis());
    }

    this.support = new GenericObjectPool<T>(factory, poolConfig);
}

From source file:rda.agent.client.AgentConnection.java

private void createObjectPool(Integer poolsize, String[] aghost) {
    GenericObjectPoolConfig conf = new GenericObjectPoolConfig();
    conf.setMaxIdle(poolsize);//from   w ww .  j a va 2s.co m
    conf.setMaxTotal(poolsize);

    this._pool = new GenericObjectPool<>(new AgentClientFactory(aghost[0], aghost[1], aghost[2]), conf);

    System.out.println("***********************************************************");
    System.out.println("total:" + ((GenericObjectPool) _pool).getMaxTotal() + " , minIdle:"
            + ((GenericObjectPool) _pool).getMinIdle() + " , maxIdle:"
            + ((GenericObjectPool) _pool).getMaxIdle());
    System.out.println("***********************************************************");

    this.aghost = aghost;
}

From source file:spnodechecker.client.ConnectionPool.java

public ConnectionPool(String url) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(200);/*  w  w w.  j a va2 s.  c om*/
    this.connectionPool = new GenericObjectPool(new ConnectionPooledFactory(url), config);
}

From source file:stroom.pool.AbstractPoolCacheBean.java

@Override
protected ObjectPool<PoolItem<K, V>> create(final K key) {
    final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1000);/*from  w w w .  jav  a2s.c o m*/
    config.setMaxIdle(1000);
    config.setBlockWhenExhausted(false);

    return new GenericObjectPool<>(new ObjectFactory<>(this, key), config);
}

From source file:stroom.statistics.server.sql.SQLStatisticEventStore.java

private void initPool(final GenericObjectPoolConfig config) {
    objectPool = new GenericObjectPool<>(new ObjectFactory(), config);

}

From source file:za.co.wilderness.WildernessPoolingDriver.java

private void setupDriver() throws Exception {

    String jdbcDriverName = "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource";

    try {/*  w  w w  .  ja  v a2s . c o m*/
        java.lang.Class.forName(jdbcDriverName).newInstance();
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        //System.out.println("Error when attempting to obtain DB Driver: " + jdbcDriverName + " on "+ new Date().toString() + e.getMessage());
        logger.log(Level.SEVERE,
                "Error when attempting to obtain DB Driver: " + jdbcDriverName + " on " + new Date().toString(),
                e);
        throw new Exception(e);
    }

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(this.connectURI, this.properties);

    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            null);

    GenericObjectPoolConfig genConfig = new GenericObjectPoolConfig();
    genConfig.setMaxIdle(this.config.getMaxIdle());
    genConfig.setMaxTotal(this.config.getMaxActive());
    genConfig.setMinIdle(this.config.getMinIdle());
    genConfig.setMaxWaitMillis(this.config.getMaxWaitMillis());
    genConfig.setTimeBetweenEvictionRunsMillis(5000);
    genConfig.setTestWhileIdle(true);

    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory,
            genConfig);

    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);

    //
    // Finally, we create the PoolingDriver itself...
    //
    Class.forName("org.apache.commons.dbcp2.PoolingDriver");
    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
    //System.out.println("Driver : " + driver.toString());
    logger.log(Level.FINE, "Driver : " + driver.toString());

    //
    // ...and register our pool with it.
    //
    driver.registerPool(EXTERNAL_SERVICE.name(), connectionPool);

    //
    // Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
    // to access our pool of Connections.
    //
}