use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class Case3 method dbcp.
public void dbcp() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setInitialSize(initialSize);
dataSource.setMaxActive(maxActive);
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();
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class CaseKylin_mysql method dbcp.
public void dbcp() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setInitialSize(initialSize);
dataSource.setMaxActive(maxActive);
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();
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class Oracle_Case0 method test_1.
public void test_1() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setInitialSize(initialSize);
dataSource.setMaxActive(maxActive);
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();
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class Oracle_Case4 method test_dbcp.
public void test_dbcp() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setMaxActive(maxActive);
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);
for (int i = 0; i < loopCount; ++i) {
p0(dataSource, "dbcp", threadCount);
}
System.out.println();
}
use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.
the class DBCPTest method test_max.
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);
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());
}
Aggregations