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: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);
    dataSource.setMinIdle(minPoolSize);//from w w  w.j a  va  2  s  .c  o m
    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);
    dataSource.setMinIdle(minIdle);//from   ww w .  ja  v a 2  s  .  c om
    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);
    dataSource.setMinIdle(minIdle);//  www  .  ja v a 2  s  .c o  m
    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.DBCPTest.java

public void test_max() throws Exception {
    Class.forName("com.alibaba.druid.mock.MockDriver");

    final BasicDataSource dataSource = new BasicDataSource();
    //        final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setInitialSize(3);// w  w  w .j  av a  2s.  co m
    dataSource.setMaxActive(20);
    dataSource.setMaxIdle(20);
    dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
    dataSource.setUrl("jdbc:mock:xxx");

    final int THREAD_COUNT = 200;
    final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
    final CountDownLatch startLatch = new CountDownLatch(1);
    Thread[] threads = new Thread[THREAD_COUNT];
    for (int i = 0; i < THREAD_COUNT; ++i) {
        threads[i] = new Thread() {

            public void run() {
                try {
                    startLatch.await();
                    for (int i = 0; i < 1000; ++i) {
                        Connection conn = dataSource.getConnection();
                        Thread.sleep(1);
                        conn.close();
                    }
                } catch (Exception e) {
                } finally {
                    endLatch.countDown();
                }
            }
        };
        threads[i].start();
    }

    startLatch.countDown();

    endLatch.await();

    //        System.out.println(dataSource.getNumIdle());
    System.out.println(MockDriver.instance.getConnections().size());
    System.out.println(MockDriver.instance.getConnectionCloseCount());
}

From source file:jp.go.nict.langrid.serviceexecutor.db.ConnectionManager.java

private void initWithBasicDataSource(String driverClassName, String connectionUrl, String userName,
        String password, int maxActive, int maxIdle, int maxWait, int maxPSActive) {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(driverClassName);
    bds.setUrl(connectionUrl);/*from  ww  w  . j  a  va 2  s.co  m*/
    bds.setUsername(userName);
    bds.setPassword(password);
    bds.setMaxActive(maxActive);
    bds.setMaxIdle(maxIdle);
    bds.setMaxWait(maxWait);
    if (maxPSActive != -1) {
        bds.setMaxOpenPreparedStatements(maxPSActive);
    }
    this.dataSource = bds;
}

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);
    dataSource.setMaxIdle(maxIdle);/*from   w ww  .  java2  s .  c om*/
    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.manpowergroup.cn.icloud.util.Case1.java

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMinIdle(minPoolSize);/*from  ww w  . j a  va 2 s . c o m*/
    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();
}

From source file:com.spankr.tutorial.ConnectionDAO.java

/**
 * Git me mah datasource!/*from   w  w  w .  java  2 s  .  c o m*/
 * 
 * @return datasource pointing at the DEV version of partsearch
 */
public DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    ds.setUrl("jdbc:hsqldb:mem:sampleDB");
    ds.setUsername("SA");
    ds.setPassword("");
    ds.setInitialSize(2);
    ds.setMaxActive(20);
    return ds;
}

From source file:Metodos.Pool.java

private void inicializaDataSource() {

    BasicDataSource basicDataSource = new BasicDataSource();

    //basicDataSource.setDriverClassName("org.gjt.mm.mysql.Driver");
    basicDataSource.setUsername(user);//  ww  w. ja va2s .  com
    basicDataSource.setPassword(pass);
    basicDataSource.setUrl(url);
    basicDataSource.setMaxActive(50);

    dataSource = basicDataSource;

}

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 ww  .ja v  a  2  s .  co 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();
}