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

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

Introduction

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

Prototype

public synchronized void setMaxIdle(int maxIdle) 

Source Link

Document

Sets the maximum number of connections that can remain idle in the pool.

Usage

From source file:edu.emory.cci.aiw.i2b2etl.ConfigurationFactory.java

private static BasicDataSource newBasicDataSource(String url) {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(DRIVER_CLASS_NAME);
    bds.setUrl(url);//from www . j  ava 2  s  .c  o m
    bds.setMinIdle(MIN_IDLE);
    bds.setMaxIdle(MAX_IDLE);
    bds.setMaxTotal(MAX_TOTAL);
    return bds;
}

From source file:com.github.akiraly.db4j.pool.DbcpUtils.java

public static BasicDataSource newDefaultDS() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDefaultAutoCommit(false);

    dataSource.setDefaultQueryTimeout(1);
    dataSource.setValidationQueryTimeout(1);
    dataSource.setMaxWaitMillis(5000);/*ww  w  . j  a  va  2 s . co  m*/

    dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

    dataSource.setInitialSize(4);
    dataSource.setMinIdle(4);
    dataSource.setMaxIdle(8);
    dataSource.setMaxTotal(16);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(128);
    return dataSource;
}

From source file:dgw.mt940.db.util.DGWBasicDataSource.java

public static DataSource setupDataSource(String connectURI, String driver, String userName, String password,
        String removeAbandoned, String initSize, String mxSize) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);//from  w w w.ja va2  s . c  o  m
    ds.setUrl(connectURI);
    ds.setUsername(userName);
    ds.setPassword(password);
    ds.setUrl(connectURI);
    ds.setAbandonedUsageTracking(Boolean.getBoolean(removeAbandoned));
    ds.setInitialSize(Integer.parseInt(initSize));
    ds.setMaxIdle(Integer.parseInt(mxSize));
    return ds;
}

From source file:de.anycook.db.mysql.DBHandler.java

private static BasicDataSource setupDataSource(String server, int port, String dbName, String username,
        String password, int maxActive, int maxIdle) {
    Preconditions.checkNotNull(server);/*from w  w w.  j av  a2 s. c  o m*/
    Preconditions.checkNotNull(dbName);
    Preconditions.checkNotNull(username);

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername(username);

    if (password.length() > 0) {
        ds.setPassword(password);
    }

    String url = String.format("jdbc:mysql://%s:%d/%s?useConfigs=maxPerformance&useCompression=true", server,
            port, dbName);
    ds.setUrl(url);
    ds.setValidationQuery("SELECT 1;");
    ds.setTestWhileIdle(true);
    ds.setTestOnReturn(true);
    ds.setMaxTotal(maxActive);
    ds.setMaxIdle(maxIdle);
    ds.setRemoveAbandonedOnBorrow(true);
    ds.setRemoveAbandonedTimeout(60);

    if (Configuration.getInstance().isDeveloperMode()) {
        ds.setLogAbandoned(true);
    }

    sLogger.info("created new Connectionpool");
    return ds;
}

From source file:com.tukaloff.customers.Config.java

@Bean
public BasicDataSource dataSource() {
    BasicDataSource dbcp = new BasicDataSource();
    dbcp.setDriverClassName("com.mysql.jdbc.Driver");
    dbcp.setInitialSize(5);/* w  w w . j a va  2s. com*/
    dbcp.setMaxIdle(10);
    return dbcp;
}

From source file:co.id.ipb.ilkom.training.db.SpringDataJpaConfiguration.java

@Bean
DataSource dataSource() {/*from   w ww .j  a  v  a  2s  .  c o  m*/
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:mysql://localhost:3306/trainingjava");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    dataSource.setInitialSize(20);
    dataSource.setMaxIdle(20);
    dataSource.setMaxTotal(100);
    return dataSource;
}

From source file:com.mycompany.configuration.SpringDateConfigMySQL.java

@Bean
//? ? /*from   w  ww  . j  a v  a  2 s  .  c o m*/
public DataSource dataSource() {
    //MySQL
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    //? 
    ds.setUrl("jdbc:mysql://localhost:3306/dateexam");
    ds.setUsername("root");
    ds.setPassword("root");
    /* ds.setUsername("exam");
    ds.setPassword("exam68");*/
    //
    ds.setInitialSize(5);
    ds.setMaxIdle(5);
    ds.setMaxTotal(15);

    return ds;
}

From source file:com.thoughtworks.go.server.service.BackupServiceH2IntegrationTest.java

private BasicDataSource constructTestDataSource(File file) {
    BasicDataSource source = new BasicDataSource();
    source.setDriverClassName("org.h2.Driver");
    source.setUrl("jdbc:h2:" + file.getAbsolutePath() + "/cruise;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    source.setUsername("sa");
    source.setPassword("");
    source.setMaxTotal(32);//  w w w  . java2  s  . co m
    source.setMaxIdle(32);
    return source;
}

From source file:com.thoughtworks.go.server.database.H2Database.java

private void configureDataSource(BasicDataSource source, String url) {
    String databaseUsername = configuration.getUser();
    String databasePassword = configuration.getPassword();
    LOG.info("[db] Using connection configuration {} [User: {}]", url, databaseUsername);
    source.setDriverClassName("org.h2.Driver");
    source.setUrl(url);/*from   ww w .j av  a 2s  .c  o  m*/
    source.setUsername(databaseUsername);
    source.setPassword(databasePassword);
    source.setMaxTotal(configuration.getMaxActive());
    source.setMaxIdle(configuration.getMaxIdle());
}

From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java

/**
 * Parses the ds./*from   w  w  w.j av a2  s .  c  o  m*/
 */
protected void parseDs() {
    // db.ds.rogerdb.name=RogersOracle
    // db.ds.rogerdb.drivername=oracle.jdbc.driver.OracleDriver
    // db.ds.rogerdb.url=jdbc:oracle:thin:@localhost:1521:rogdb
    // db.ds.rogerdb.username=genome
    // db.ds.rogerdb.password=genome
    List<String> dse = localSettings.getKeysPrefixWithInfix("db.ds", "name");
    for (String dsn : dse) {
        String key = dsn + ".name";
        String name = localSettings.get(key);
        if (StringUtils.isBlank(name) == true) {
            log.error("Name in local-settings is not defined with key: " + key);
            continue;
        }
        key = dsn + ".drivername";
        String driverName = localSettings.get(key);
        if (StringUtils.isBlank(name) == true) {
            log.error("drivername in local-settings is not defined with key: " + key);
            continue;
        }
        key = dsn + ".url";
        String url = localSettings.get(key);
        if (StringUtils.isBlank(name) == true) {
            log.error("url in local-settings is not defined with key: " + key);
            continue;
        }
        key = dsn + ".username";
        String userName = localSettings.get(key);
        key = dsn + ".password";
        String password = localSettings.get(key);
        BasicDataSource bd = dataSourceSuplier.get();

        bd.setDriverClassName(driverName);
        bd.setUrl(url);
        bd.setUsername(userName);
        bd.setPassword(password);
        bd.setMaxTotal(localSettings.getIntValue(dsn + ".maxActive",
                GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY));
        bd.setMaxIdle(localSettings.getIntValue(dsn + ".maxIdle",
                GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY));
        bd.setMinIdle(localSettings.getIntValue(dsn + ".minIdle",
                GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY));
        bd.setMaxWaitMillis(localSettings.getLongValue(dsn + ".maxWait",
                GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS));
        bd.setInitialSize(localSettings.getIntValue(dsn + ".intialSize", 0));
        bd.setDefaultCatalog(localSettings.get(dsn + ".defaultCatalog", null));
        bd.setDefaultAutoCommit(localSettings.getBooleanValue(dsn + ".defaultAutoCommit", true));
        bd.setValidationQuery(localSettings.get(dsn + ".validationQuery", null));
        bd.setValidationQueryTimeout(localSettings.getIntValue(dsn + ".validationQueryTimeout", -1));
        dataSources.put(name, bd);
    }
}