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

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

Introduction

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

Prototype

public synchronized void setMaxIdle(int maxIdle) 

Source Link

Document

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

Usage

From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java

public void test_dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setMaxActive(maxActive);/*from   w ww .j  a v  a 2 s  . c om*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(preparedStatementCache);
    dataSource.setMaxOpenPreparedStatements(preparedStatementCacheSize);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setConnectionProperties(properties);

    //        printAV_INFO(dataSource);

    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.alibaba.druid.pool.dbcp.Test0.java

public void test_idle() throws Exception {
    MockDriver driver = MockDriver.instance;

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
    dataSource.setInitialSize(0);/*from  w  w  w  . j  a v a  2s .c  o m*/
    dataSource.setMaxActive(4);
    dataSource.setMaxIdle(4);
    dataSource.setMinIdle(1);
    dataSource.setMinEvictableIdleTimeMillis(5000 * 1);
    dataSource.setTimeBetweenEvictionRunsMillis(10);
    dataSource.setTestWhileIdle(false);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");

    {
        Connection conn = dataSource.getConnection();

        // Assert.assertEquals(dataSource.getInitialSize(), driver.getConnections().size());
        System.out.println("raw size : " + driver.getConnections().size());

        conn.close();
        System.out.println("raw size : " + driver.getConnections().size());
    }

    {
        Connection conn = dataSource.getConnection();

        // Assert.assertEquals(dataSource.getInitialSize(), driver.getConnections().size());
        System.out.println("raw size : " + driver.getConnections().size());

        conn.close();
        System.out.println("raw size : " + driver.getConnections().size());
    }

    dataSource.close();
}

From source file:com.alibaba.druid.benckmark.pool.Oracle_Case0.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*w  w w.  j a  v  a2  s  .c  o m*/
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(true);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }
    System.out.println();
}

From source file:com.alibaba.druid.benckmark.pool.Case_Concurrent_50.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from w w  w .  j ava  2s .  c o m*/
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }

    System.out.println();
}

From source file:com.manpowergroup.cn.icloud.util.Case0.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);// w  w  w . j  a va2 s .co m
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }
    System.out.println();
}

From source file:com.alibaba.druid.benckmark.pool.CaseKylin_mysql.java

public void dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/* ww  w .j  av  a  2  s  .  co  m*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnBorrow(testWhileIdle);
    dataSource.setTestOnBorrow(testOnReturn);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);

    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.alibaba.druid.benckmark.pool.CaseKylin_Oracle.java

public void dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from   w ww.j  a  v a2s. c om*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(oracleDriverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnBorrow(testWhileIdle);
    dataSource.setTestOnBorrow(testOnReturn);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    dataSource.setValidationQuery(validateQuery);

    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.lawulu.bdc.etl.batch.config.DatabaseConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dbcpDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    dataSource.setMaxActive(20);/*from  ww w. j ava  2 s .  c om*/
    dataSource.setMaxIdle(20);
    dataSource.setMaxWait(10000);
    dataSource.setInitialSize(5);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    return dataSource;
}

From source file:com.agiletec.ConfigTestUtils.java

private void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder,
        Properties testConfig) {/* w  w w  . j a  v  a 2  s . c o m*/
    String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName");
    try {
        String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName");
        String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url");
        String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username");
        String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password");
        Class.forName(className);
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setMaxActive(8);
        ds.setMaxIdle(4);
        ds.setDriverClassName(className);
        builder.bind("java:comp/env/jdbc/" + beanName, ds);
    } catch (Throwable t) {
        throw new RuntimeException("Error on creation datasource '" + beanName + "'", t);
    }
}

From source file:com.manpowergroup.cn.icloud.util.Case1.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//w  w  w  .ja v a  2s .  co m
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(false);

    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}