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

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

Introduction

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

Prototype

public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) 

Source Link

Document

Sets the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).

Usage

From source file:com.stehno.sanctuary.core.Sanctuary.java

private static DataSource createDataSource() throws ClassNotFoundException {
    SharedPoolDataSource poolDataSource = new SharedPoolDataSource();

    DriverAdapterCPDS cpds = new DriverAdapterCPDS();
    cpds.setDriver("org.h2.Driver");
    cpds.setUrl("jdbc:h2:/home/cjstehno/h2/sanctuary");
    cpds.setUser("sa");
    cpds.setPassword("");

    poolDataSource.setConnectionPoolDataSource(cpds);
    poolDataSource.setMaxActive(10);//  w  ww  . ja v  a  2 s .  c  o m
    poolDataSource.setMaxIdle(5);
    poolDataSource.setMinEvictableIdleTimeMillis(1000);
    poolDataSource.setTestWhileIdle(true);
    poolDataSource.setValidationQuery("select 1");

    return poolDataSource;
}

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  .ja v a 2 s.  c om
 */
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 ...");
    }
}