Example usage for org.apache.commons.pool2.impl AbandonedConfig setRemoveAbandonedTimeout

List of usage examples for org.apache.commons.pool2.impl AbandonedConfig setRemoveAbandonedTimeout

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl AbandonedConfig setRemoveAbandonedTimeout.

Prototype

public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) 

Source Link

Document

Sets the timeout in seconds before an abandoned object can be removed

Setting this property has no effect if #getRemoveAbandonedOnBorrow() removeAbandonedOnBorrow and #getRemoveAbandonedOnMaintenance() removeAbandonedOnMaintenance are both false.

Usage

From source file:io.seldon.dbcp.DbcpFactory.java

private void createDbcp(DbcpConfig conf) {
    if (!dataSources.containsKey(conf.name)) {
        try {//ww w.  j  a v  a 2s  .  c om

            Class.forName(conf.driverClassName);

            DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory(conf.jdbc, conf.user,
                    conf.password);

            PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, null);
            pcf.setValidationQuery(conf.validationQuery);
            //, pool, null, conf.validationQuery, false, true,abandondedConfig);

            logger.info("Creating pool " + conf.toString());
            // create a generic pool
            GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pcf);
            pool.setMaxTotal(conf.maxTotal);
            pool.setMaxIdle(conf.maxIdle);
            pool.setMinIdle(conf.minIdle);
            pool.setMaxWaitMillis(conf.maxWait);
            pool.setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
            pool.setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
            pool.setTestWhileIdle(conf.testWhileIdle);
            pool.setTestOnBorrow(conf.testOnBorrow);

            AbandonedConfig abandonedConfig = new AbandonedConfig();
            abandonedConfig.setRemoveAbandonedOnMaintenance(conf.removeAbanadoned);
            abandonedConfig.setRemoveAbandonedTimeout(conf.removeAbandonedTimeout);
            abandonedConfig.setLogAbandoned(conf.logAbandonded);

            pool.setAbandonedConfig(abandonedConfig);

            pcf.setPool(pool);
            DataSource ds = new PoolingDataSource(pool);
            dataSources.put(conf.name, ds);

        } catch (ClassNotFoundException e) {
            logger.error(
                    "Failed to create datasource for " + conf.name + " with class " + conf.driverClassName);
        }

    } else {
        logger.error("Pool " + conf.name + " already exists. Can't change existing datasource at present.");
    }
}

From source file:ddf.ldap.ldaplogin.LdapLoginConfig.java

private AbandonedConfig createGenericPoolAbandonConfig() {
    AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setRemoveAbandonedTimeout(FIVE_MIN_S);
    return abandonedConfig;
}