org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory Java Examples

The following examples show how to use org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RiceXADataSource.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected KeyedObjectPoolFactory createStatementPoolFactory() {
	return new GenericKeyedObjectPoolFactory(null, 
               -1, // unlimited maxActive (per key)
               GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 
               0, // maxWait
               1, // maxIdle (per key) 
               getPreparedStatementCacheSize()); 
}
 
Example #2
Source File: DbWrapper.java    From wisp with Apache License 2.0 4 votes vote down vote up
private DataSource setupDataSource(String driver, String connectURI,
                                   String userName, String passwd) throws ClassNotFoundException {

    // driver
    Class.forName(driver);

    //
    // First, we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    // 设置在getConnection时验证Connection是否有效
    connectionPool.setTestOnBorrow(true);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
            connectURI, userName, passwd);

    // null can be used as parameter because this parameter is set in
    // PoolableConnectionFactory when creating a new PoolableConnection
    KeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory(
            null);

    //
    // Now we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    new PoolableConnectionFactory(connectionFactory, connectionPool,
            statementPool, "select now()", false, true);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
}