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

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

Introduction

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

Prototype

public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) 

Source Link

Document

Sets the number of milliseconds to sleep between runs of the idle object evictor thread.

Usage

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

/**
 * jdbc?  ??  .//www .  ja  v a2s. com
 * @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();
    }
}