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.Case3.java

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);// w ww .j ava 2 s.  c  o  m
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setMinIdle(minIdle);
    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.setConnectionProperties(connectionProperties);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

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

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/* ww w  .  j  av a  2  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("SELECT 1");
    dataSource.setTestOnBorrow(testOnBorrow);

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

From source file:com.mmnaseri.dragonfly.sample.Config.java

@Bean
public DataSource dataSource(DatabaseDialect dialect, @Value("${db.username}") String username,
        @Value("${db.password}") String password, @Value("${db.database}") String database) {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(dialect.getDriverClassName());
    dataSource.setUrl("jdbc:mysql://localhost/" + database);
    dataSource.setUsername(username);/*from w  w  w  .j  a  v  a  2 s . c  om*/
    dataSource.setPassword(password);
    dataSource.setMaxActive(200);
    dataSource.setMaxIdle(100);
    dataSource.setMaxWait(1500);
    return dataSource;
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from  w  w w .  j  av  a  2  s .c om*/
    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.emc.ecs.sync.service.MySQLDbService.java

@Override
protected JdbcTemplate createJdbcTemplate() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(connectString);/*from w  w w.  j  ava 2  s .c  o m*/
    ds.addConnectionProperty("characterEncoding", "UTF-8");
    if (username != null)
        ds.setUsername(username);
    if (password != null)
        ds.setPassword(password);
    ds.setMaxActive(1000);
    ds.setMaxIdle(1000);
    ds.setMaxOpenPreparedStatements(1000);
    ds.setPoolPreparedStatements(true);
    return new JdbcTemplate(ds);
}

From source file:gestores.PoolDeConexiones.java

protected void pedirConexion() throws Exception {
    if (conexion == null) {
        try {// ww  w  .jav  a 2 s .c  o m
            BasicDataSource basicDataSource = new BasicDataSource();
            basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
            basicDataSource.setUrl("jdbc:mysql://localhost:3306/osg");
            basicDataSource.setUsername("root");
            basicDataSource.setPassword("root");
            basicDataSource.setMaxActive(20);
            basicDataSource.setMaxIdle(2);
            conexion = basicDataSource.getConnection();
            conexion.setAutoCommit(false);
        } catch (SQLException e) {
            throw new Exception(e.getMessage());
        }
    }
}

From source file:jp.classmethod.aws.brian.config.DataSourceConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
    basicDataSource.setUrl(url);//from w w  w. ja  va  2 s .  c  o m
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    basicDataSource.setValidationQuery("SELECT 1");
    basicDataSource.setMaxActive(50);
    basicDataSource.setMaxIdle(10);
    basicDataSource.setMinIdle(5);
    return basicDataSource;
}

From source file:hoot.services.testsupport.HootServicesSpringTestConfig.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.postgresql.Driver");
    dataSource.setUrl("jdbc:postgresql://localhost:5432/hoot");
    dataSource.setUsername("hoot");
    dataSource.setPassword("hoottest");
    dataSource.setInitialSize(5);//from  w w  w .j a  va  2  s.  c  o  m
    dataSource.setMaxActive(10);
    dataSource.setMaxIdle(2);
    dataSource.setDefaultAutoCommit(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setLogAbandoned(true);
    return dataSource;
}

From source file:calculus.backend.JpaConfig.java

@Bean
public DataSource dataSource() {

    loadProperties();//from  w  ww.jav  a  2 s .  c  o m

    BasicDataSource driver = new BasicDataSource();
    driver.setDriverClassName(this.driver);
    driver.setUrl(this.url);
    driver.setUsername(this.user);
    driver.setPassword(this.pass);
    driver.setMaxIdle(poolSize);
    driver.setMaxActive(poolSize);
    return driver;
}

From source file:net.certifi.audittablegen.GenericDMR.java

/**
 * Generate a DataSource from Properties 
 * @param props/*  w w  w  . j a  va 2s  .  co m*/
 * @return BasicDataSource as DataSource
 */
static DataSource getRunTimeDataSource(Properties props) {

    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(props.getProperty("driver", ""));
    dataSource.setUsername(props.getProperty("username"));
    dataSource.setPassword(props.getProperty("password"));
    dataSource.setUrl(props.getProperty("url"));
    dataSource.setMaxActive(10);
    dataSource.setMaxIdle(5);
    dataSource.setInitialSize(5);

    //dataSource.setValidationQuery("SELECT 1");

    return dataSource;
}