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

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

Introduction

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

Prototype

public synchronized void setMaxActive(int maxActive) 

Source Link

Document

Sets the maximum number of active connections that can be allocated at the same time.

Usage

From source file:gestores.PoolDeConexiones.java

protected void pedirConexion() throws Exception {
    if (conexion == null) {
        try {//from ww w.j  a  va  2  s  .  co 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:com.alibaba.cobar.manager.dao.delegate.DataSourceCreator.java

@Override
public DataSource createDataSource(String ip, int port, String user, String password) {
    BasicDataSource ds = new BasicDataSource();
    ds.setUsername(user);/*from   w ww .  j  a v  a  2s. c  om*/
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(port).append("/")
            .toString());
    ds.setDriverClassName(driverClassName);
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    return ds;
}

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);//w ww . jav a2 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:com.emc.ecs.sync.service.MySQLDbService.java

@Override
protected JdbcTemplate createJdbcTemplate() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(connectString);//from w ww  .ja  v  a 2s.com
    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:io.springagora.store.ApplicationConfig.java

/**
 * Bean definition./*from  www  .ja v a  2 s .  c o  m*/
 * 
 * Datasource used to retrieve connections for the persistence layer. It's
 * configured following definitions written in {@code application.properties}.
 * 
 * @return
 *      The {@code Datasource} object, that will act as the connection pool,
 *      providing connections to the application. 
 * 
 * @throws SQLException
 *      If any error occurs during the connection attempt, it will be thrown
 *      as a {@code SQLException}.
 */
@Bean
public DataSource dataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl(connectionUrl);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setInitialSize(5);
    ds.setMaxActive(20);
    ds.setDefaultAutoCommit(false);
    return ds;
}

From source file:com.alibaba.otter.manager.biz.common.DataSourceCreator.java

private DataSource createDataSource(String url, String userName, String password, String driverClassName,
        DataMediaType dataMediaType, String encoding) {
    BasicDataSource dbcpDs = new BasicDataSource();

    dbcpDs.setInitialSize(initialSize);// ?
    dbcpDs.setMaxActive(maxActive);// ?????
    dbcpDs.setMaxIdle(maxIdle);// ??
    dbcpDs.setMinIdle(minIdle);// ?0?
    dbcpDs.setMaxWait(maxWait);// ??-1?
    dbcpDs.setRemoveAbandoned(true);// ??removeAbandonedTimeout
    dbcpDs.setLogAbandoned(true);// ??
    dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // ?
    dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// ??
    dbcpDs.setTestOnBorrow(false);// ??
    dbcpDs.setTestOnReturn(false);// ??
    dbcpDs.setTestWhileIdle(true);// ????
    dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // ????????
    dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // ???????

    // ??/*from w  ww  .j av  a  2  s . c o  m*/
    dbcpDs.setDriverClassName(driverClassName);
    dbcpDs.setUrl(url);
    dbcpDs.setUsername(userName);
    dbcpDs.setPassword(password);

    if (dataMediaType.isOracle()) {
        dbcpDs.addConnectionProperty("restrictGetTables", "true");
        // dbcpDs.setValidationQuery("select 1 from dual");
    } else if (dataMediaType.isMysql()) {
        // open the batch mode for mysql since 5.1.8
        dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
        dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
        dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 0000-00-00null
        dbcpDs.addConnectionProperty("yearIsDateType", "false");// ??year?date?
        dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// ,???
        if (StringUtils.isNotEmpty(encoding)) {
            if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
                dbcpDs.addConnectionProperty("characterEncoding", "utf8");
                dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
            } else {
                dbcpDs.addConnectionProperty("characterEncoding", encoding);
            }
        }
        // dbcpDs.setValidationQuery("select 1");
    } else {
        logger.error("ERROR ## Unknow database type");
    }

    return dbcpDs;
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMinIdle(minPoolSize);// w ww . j  a v a 2s  .co  m
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
    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();
}

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  .jav a  2s  .c o  m*/
    dataSource.setMaxActive(10);
    dataSource.setMaxIdle(2);
    dataSource.setDefaultAutoCommit(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setLogAbandoned(true);
    return dataSource;
}

From source file:com.dangdang.ddframe.rdb.sharding.spring.AbstractSpringDBUnitTest.java

private DataSource createDataSource(final String dataSetFile) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(org.h2.Driver.class.getName());
    result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL",
            getFileName(dataSetFile)));/*from  w  w w.  j  a v a 2s. com*/
    result.setUsername("sa");
    result.setPassword("");
    result.setMaxActive(100);
    return result;
}

From source file:com.dangdang.ddframe.rdb.integrate.AbstractDBUnitTest.java

private DataSource createDataSource(final String dataSetFile) {
    if (DATA_SOURCES.containsKey(dataSetFile)) {
        return DATA_SOURCES.get(dataSetFile);
    }/*from   w  w  w  .j a  va2s.c om*/
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(dbEnv.getDriverClassName());
    result.setUrl(dbEnv.getURL(getFileName(dataSetFile)));
    result.setUsername(dbEnv.getUsername());
    result.setPassword(dbEnv.getPassword());
    result.setMaxActive(1000);
    DATA_SOURCES.put(dataSetFile, result);
    return result;
}