System.out.println("[testPoolThreads20Connections10Validate]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
tearDown();\r
}\r
+ \r
+ public void testDBCPThreads10Connections10WithQuery() throws Exception {\r
+ init();\r
+ this.datasource.getPoolProperties().setMaxActive(10);\r
+ this.datasource.getPoolProperties().setTestOnBorrow(false);\r
+ this.threadcount = 10;\r
+ this.transferProperties();\r
+ this.tDatasource.getConnection().close();\r
+ latch = new CountDownLatch(threadcount);\r
+ long start = System.currentTimeMillis();\r
+ for (int i=0; i<threadcount; i++) {\r
+ TestThread t = new TestThread();\r
+ t.setName("tomcat-dbcp-"+i);\r
+ t.d = this.tDatasource;\r
+ t.query = "select * from user";\r
+ t.start();\r
+ }\r
+ latch.await();\r
+ long delta = System.currentTimeMillis() - start;\r
+ System.out.println("[testDBCPThreads10Connections10WithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+ tearDown();\r
+ }\r
\r
+ public void testPoolThreads10Connections10WithQuery() throws Exception {\r
+ init();\r
+ this.datasource.getPoolProperties().setMaxActive(10);\r
+ this.datasource.getPoolProperties().setTestOnBorrow(false);\r
+ this.threadcount = 10;\r
+ this.transferProperties();\r
+ this.datasource.getConnection().close();\r
+ latch = new CountDownLatch(threadcount);\r
+ long start = System.currentTimeMillis();\r
+ for (int i=0; i<threadcount; i++) {\r
+ TestThread t = new TestThread();\r
+ t.setName("tomcat-pool-"+i);\r
+ t.d = DataSourceFactory.getDataSource(this.datasource);\r
+ t.query = "select * from user";\r
+ t.start();\r
+ }\r
+ latch.await();\r
+ long delta = System.currentTimeMillis() - start;\r
+ System.out.println("[testPoolThreads10Connections10WithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+ tearDown();\r
+ }\r
+ \r
+ public void testDBCPThreads10Connections10WithValidateWithQuery() throws Exception {\r
+ init();\r
+ this.datasource.getPoolProperties().setMaxActive(10);\r
+ this.datasource.getPoolProperties().setTestOnBorrow(true);\r
+ this.datasource.getPoolProperties().setValidationQuery("SELECT 1");\r
+ this.threadcount = 10;\r
+ this.transferProperties();\r
+ this.tDatasource.getConnection().close();\r
+ latch = new CountDownLatch(threadcount);\r
+ long start = System.currentTimeMillis();\r
+ for (int i=0; i<threadcount; i++) {\r
+ TestThread t = new TestThread();\r
+ t.setName("tomcat-dbcp-"+i);\r
+ t.d = this.tDatasource;\r
+ t.query = "select * from user";\r
+ t.start();\r
+ }\r
+ latch.await();\r
+ long delta = System.currentTimeMillis() - start;\r
+ System.out.println("[testDBCPThreads10Connections10WithValidateWithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+ tearDown();\r
+ }\r
+\r
+ public void testPoolThreads10Connections10WithValidateWithQuery() throws Exception {\r
+ init();\r
+ this.datasource.getPoolProperties().setMaxActive(10);\r
+ this.datasource.getPoolProperties().setTestOnBorrow(true);\r
+ this.datasource.getPoolProperties().setValidationQuery("SELECT 1");\r
+ this.threadcount = 10;\r
+ this.transferProperties();\r
+ this.datasource.getConnection().close();\r
+ latch = new CountDownLatch(threadcount);\r
+ long start = System.currentTimeMillis();\r
+ for (int i=0; i<threadcount; i++) {\r
+ TestThread t = new TestThread();\r
+ t.setName("tomcat-pool-"+i);\r
+ t.d = DataSourceFactory.getDataSource(this.datasource);\r
+ t.query = "select * from user";\r
+ t.start();\r
+ }\r
+ latch.await();\r
+ long delta = System.currentTimeMillis() - start;\r
+ System.out.println("[testPoolThreads10Connections10WithValidateWithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+ tearDown();\r
+ }\r
\r
public class TestThread extends Thread {\r
protected DataSource d;\r
- \r
+ protected String query = null;\r
public void run() {\r
long max = -1, totalmax=0, totalcmax=0, cmax = -1, nroffetch = 0, totalruntime = 0;\r
try {\r
totalmax += delta;\r
max = Math.max(delta, max);\r
nroffetch++;\r
+ if (query!=null) {\r
+ Statement st = con.createStatement();\r
+ ResultSet rs = st.executeQuery(query);\r
+ while (rs.next()) {\r
+ }\r
+ rs.close();\r
+ st.close();\r
+ }\r
} finally {\r
long cstart = System.nanoTime();\r
if (con!=null) try {con.close();}catch(Exception x) {x.printStackTrace();}\r