List of usage examples for org.apache.commons.dbcp BasicDataSource setInitialSize
public synchronized void setInitialSize(int initialSize)
Sets the initial size of the connection pool.
Note: this method currently has no effect once the pool has been initialized.
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);/*ww w . j ava 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(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);// w w w .j av a 2 s . com 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 v a2 s . 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.Case1.java
public void test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/* w w w. j a v a 2 s . com*/ 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(); }
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); dataSource.setMaxActive(20);/* ww w . j a va 2 s . c o m*/ 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:com.spankr.tutorial.ConnectionDAO.java
/** * Git me mah datasource!/*from w ww . java2 s . com*/ * * @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:com.alibaba.druid.benckmark.pool.Case2.java
public void test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);// www .ja v a2 s .com 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.alibaba.druid.benckmark.pool.CaseKylin_mysql.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from w w w. ja va 2s .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.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); dataSource.setMaxActive(4);/*from w w w . jav a2 s. c om*/ 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.CaseKylin_Oracle.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);// w w w . ja v a 2 s .co m 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(); }