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

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

Introduction

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

Prototype

byte WHEN_EXHAUSTED_GROW

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

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 simply create a new object anyway.

Usage

From source file:sce.ConnectionPool.java

/**
 *
 * @return @throws Exception//from w w w .j  a  v a  2  s  .c om
 */
public DataSource setUp() throws Exception {
    /**
     * Load JDBC Driver class.
     */
    Class.forName(ConnectionPool.DRIVER).newInstance();

    /**
     * Creates an instance of GenericObjectPool that holds our pool of
     * connections object.
     */
    connectionPool = new GenericObjectPool();
    // set the max number of connections
    connectionPool.setMaxActive(connections);
    // if the pool is exhausted (i.e., the maximum number of active objects has been reached), the borrowObject() method should simply create a new object anyway
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);

    /**
     * Creates a connection factory object which will be used by the pool to
     * create the connection object. We pass the JDBC url info, username
     * and password.
     */
    ConnectionFactory cf = new DriverManagerConnectionFactory(ConnectionPool.URL, ConnectionPool.USERNAME,
            ConnectionPool.PASSWORD);

    /**
     * Creates a PoolableConnectionFactory that will wrap the connection
     * object created by the ConnectionFactory to add object pooling
     * functionality.
     */
    PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, connectionPool, null, null, false, true);
    return new PoolingDataSource(connectionPool);
}

From source file:utility.ConnectionPool.java

/**
 *
 * @return @throws Exception//from  w  w w  .  j a v  a2 s  .  co m
 */
public DataSource setUp() throws Exception {
    /**
     * Load JDBC Driver class.
     */
    Class.forName(ConnectionPool.DRIVER).newInstance();

    /**
     * Creates an instance of GenericObjectPool that holds our pool of
     * connections object.
     */
    connectionPool = new GenericObjectPool();
    // set the max number of connections
    connectionPool.setMaxActive(connections);
    // if the pool is exhausted (i.e., the maximum number of active objects has been reached), the borrowObject() method should simply create a new object anyway
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);

    /**
     * Creates a connection factory object which will be use by the pool to
     * create the connection object. We passes the JDBC url info, username and
     * password.
     */
    ConnectionFactory cf = new DriverManagerConnectionFactory(URL, USERNAME, PASSWORD);

    /**
     * Creates a PoolableConnectionFactory that will wraps the connection object
     * created by the ConnectionFactory to add object pooling functionality.
     */
    PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, connectionPool, null, null, false, true);
    return new PoolingDataSource(connectionPool);
}