Example usage for org.apache.commons.dbcp2 BasicDataSource setMinIdle

List of usage examples for org.apache.commons.dbcp2 BasicDataSource setMinIdle

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 BasicDataSource setMinIdle.

Prototype

public synchronized void setMinIdle(int minIdle) 

Source Link

Document

Sets the minimum number of idle connections in the pool.

Usage

From source file:org.springframework.boot.autoconfigure.jdbc.metadata.CommonsDbcp2DataSourcePoolMetadataTests.java

private CommonsDbcp2DataSourcePoolMetadata createDataSourceMetadata(int minSize, int maxSize) {
    BasicDataSource dataSource = createDataSource();
    dataSource.setMinIdle(minSize);
    dataSource.setMaxTotal(maxSize);//from ww  w  .  ja v  a2  s.  co m
    return new CommonsDbcp2DataSourcePoolMetadata(dataSource);
}

From source file:uk.co.platosys.db.jdbc.ConnectionBroker.java

private void init() {

    List<DatabaseCredentials> databases = properties.getDatabases();
    for (DatabaseCredentials credentials : databases) {

        String name = "";
        String driver = "";
        String userName = "";
        String password = "";
        String url = "";
        try {/*www. j a v a  2 s . com*/
            name = credentials.getName();
            logger.log("ConnectionBroker initialising database " + name);
            driver = credentials.getDriver();
            url = credentials.getUrl();
            userName = credentials.getUsername();
            password = credentials.getPassword();
            logger.log("ConnectionBroker credentials for " + name + " are " + driver + " " + url + " "
                    + userName + " " + password);

        } catch (Exception e) {
            logger.log("ConnectionBroker had a problem getting credentials for " + name, e);
        }
        /* try{
            //although we only use postgresql, there's no reason we couldn't use a different sql rdbms with a different driver for each
            //database.
        Class.forName(driver);
         }catch(ClassNotFoundException e){
        logger.log("ConnectionBroker couldn't load database driver", e);
         }*/
        try {
            /*connFac = new DriverManagerConnectionFactory(url, userName, password);
            PoolableConnectionFactory poolableConFac = new PoolableConnectionFactory(connFac, null);
            GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<PoolableConnection>(poolableConFac);
            pools.put(name, connectionPool);
            poolableConFac.setPool(connectionPool);
            PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<PoolableConnection>(connectionPool);*/
            BasicDataSource dataSource = new BasicDataSource();
            dataSource.setDriverClassName(driver);
            dataSource.setUsername(userName);
            dataSource.setPassword(password);
            dataSource.setUrl(url);
            dataSource.setMinIdle(2);
            dataSource.setMaxTotal(MAX_ACTIVE);
            logger.log(5, "ConnectionBroker has made BasicDataSource " + dataSource.toString());
            logger.log("Datasource " + name + " has " + dataSource.getMaxTotal() + " maxConnections");
            try {
                Connection connection = dataSource.getConnection();
                connection.close();
                dataSources.put(name, dataSource);
                dataSet.add(dataSource);
                logger.log(5, "ConnectionBroker has initialised database " + name);
            } catch (PSQLException psqe) {
                logger.log("could not make a test connection to database: " + name, psqe);
            }
        } catch (Exception e) {
            logger.log("ConnectionBroker had a problem configuring the pool with " + name, e);
        }
    }
    done = true;
}