Example usage for org.apache.commons.dbcp.datasources SharedPoolDataSource setNumTestsPerEvictionRun

List of usage examples for org.apache.commons.dbcp.datasources SharedPoolDataSource setNumTestsPerEvictionRun

Introduction

In this page you can find the example usage for org.apache.commons.dbcp.datasources SharedPoolDataSource setNumTestsPerEvictionRun.

Prototype

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) 

Source Link

Document

Sets the number of objects to examine during each run of the idle object evictor thread (if any).

Usage

From source file:com.silverpeas.wysiwyg.dynamicvalue.pool.ConnectionPoolWithJDBC.java

/**
 * Initializes the datasource. This datasource is based on the SharedPoolDataSource class, a dbcp
 * implementation/*from w w  w.j a  v  a  2 s .  co  m*/
 */
private synchronized static void initializeDatasource() {
    SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(),
            " Datasource initialization : starting ...");
    if (ds == null) {
        // check if the information for the pool creation is present.
        if (poolInfo == null) {
            SilverTrace.error("wysiwig", ConnectionPoolWithJDBC.class.toString(),
                    "wysiwig.CONNECTION_INIALIZATION_FAILED");
            throw new TechnicalException(ConnectionPoolWithJDBC.class.toString()
                    + " : An error occurred  during the connection initialization. The Pool information must be set");
        }
        SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(),
                " Datasource initialization : poolInfo detail :: " + poolInfo.toString());

        // driver registration
        DriverAdapterCPDS cpds = new DriverAdapterCPDS();
        try {
            cpds.setDriver(poolInfo.getDriver());
        } catch (ClassNotFoundException e) {
            SilverTrace.error("wysiwig", ConnectionPoolWithJDBC.class.toString(), "wysiwig.DRIVER_MISSING");
            throw new TechnicalException(ConnectionPoolWithJDBC.class.toString()
                    + " : An error occurred  during the connection initializatoin. The JDBC driver isn't in the classpath",
                    e);
        }
        cpds.setUrl(poolInfo.getUrl());
        cpds.setUser(poolInfo.getUser());
        cpds.setPassword(poolInfo.getPassword());

        // datasource object creation
        SharedPoolDataSource tds = new SharedPoolDataSource();
        tds.setConnectionPoolDataSource(cpds);
        tds.setMaxActive(poolInfo.getMaxActive());
        tds.setMaxWait(poolInfo.getMaxWait());
        tds.setMaxIdle(poolInfo.getMaxIdle());
        tds.setTimeBetweenEvictionRunsMillis(poolInfo.getTimeBetweenEvictionRunsMillis());
        tds.setNumTestsPerEvictionRun(poolInfo.getNumTestsPerEvictionRun());
        tds.setMinEvictableIdleTimeMillis(poolInfo.getMinEvictableIdleTimeMillis());
        ds = tds;
        SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(),
                " Datasource initialization : ending ...");
    }
}