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

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

Introduction

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

Prototype

public void setLogAbandoned(boolean logAbandoned) 

Source Link

Document

Sets the flag to log stack traces for application code which abandoned an object.

Usage

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

private void createDbcp(DbcpConfig conf) {
    if (!dataSources.containsKey(conf.name)) {
        try {/*from w ww  . ja v a2 s . 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.");
    }
}