Example usage for org.apache.commons.dbcp AbandonedObjectPool setMaxActive

List of usage examples for org.apache.commons.dbcp AbandonedObjectPool setMaxActive

Introduction

In this page you can find the example usage for org.apache.commons.dbcp AbandonedObjectPool setMaxActive.

Prototype

public synchronized void setMaxActive(int maxActive) 

Source Link

Document

Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time.

Usage

From source file:com.haulmont.yarg.loaders.factory.DefaultLoaderFactory.java

public static DataSource setupDataSource(String driver, String connectURI, String username, String password,
        Integer maxActive, Integer maxIdle, Integer maxWait) {
    try {/*from   w  w  w  . ja  va 2 s  . c om*/
        Class.forName(driver);
        final AbandonedConfig config = new AbandonedConfig();
        config.setLogAbandoned(true);

        AbandonedObjectPool connectionPool = new AbandonedObjectPool(null, config);

        connectionPool.setMaxIdle(maxIdle);
        connectionPool.setMaxActive(maxActive);
        if (maxWait != null) {
            connectionPool.setMaxWait(maxWait);
        }

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username,
                password);

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, null, false, true);

        connectionPool.setFactory(poolableConnectionFactory);
        PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

        return dataSource;
    } catch (ClassNotFoundException e) {
        throw new InitializationException("An error occurred during creation of new datasource object", e);
    }
}

From source file:com.haulmont.yarg.console.PropertiesSqlLoaderFactory.java

protected DataSource setupDataSource(String driver, String connectURI, String username, String password,
        Integer maxActive, Integer maxIdle, Integer maxWait) {
    try {//from  w  ww  .j ava  2s.c o m
        Class.forName(driver);
        final AbandonedConfig config = new AbandonedConfig();
        config.setLogAbandoned(true);

        AbandonedObjectPool connectionPool = new AbandonedObjectPool(null, config);

        connectionPool.setMaxIdle(maxIdle);
        connectionPool.setMaxActive(maxActive);
        if (maxWait != null) {
            connectionPool.setMaxWait(maxWait);
        }

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username,
                password);

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, null, false, true);

        connectionPool.setFactory(poolableConnectionFactory);
        return new PoolingDataSource(connectionPool);
    } catch (ClassNotFoundException e) {
        throw new InitializationException("An error occurred during creation of new datasource object", e);
    }
}

From source file:com.naver.timetable.jdbc.CubridDataManager.java

/**
 * jdbc?  ??  .//from ww w. j ava  2  s. c o  m
 * @param strDriver
 * @param strDBConn
 * @param strUserID
 * @param strUserPW
 */
public void initDriver() {
    try {
        Class.forName(strDriver);
        Connection objConn = DriverManager.getConnection(strDBConn, strUserID, strUserPW);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    // ?  ? .
    AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandoned(true);

    AbandonedObjectPool connectionPool = new AbandonedObjectPool(null, abandonedConfig);

    connectionPool.setMaxActive(maxActive);
    connectionPool.setMaxIdle(maxIdle);
    connectionPool.setMinIdle(minIdle);
    connectionPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    //      connectionPool.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    ConnectionFactory driverConnFactory = new DriverManagerConnectionFactory(strDBConn, strUserID, strUserPW);
    PoolableConnectionFactory connFactory = new PoolableConnectionFactory(driverConnFactory, connectionPool,
            null, null, defaultReadOnly, defaultAutoCommit);

    PoolingDataSource pds = new PoolingDataSource(connectionPool);
    dataSource = pds;

    try {
        for (int i = 0; i < initialSize; i++) {
            connectionPool.addObject();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}