2019独角兽企业重金招聘Python工程师标准>>>
先附上测试代码:
采用spring的junit测试工具,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 1@org.junit.Test
2public void test1() throws InterruptedException {
3 CountDownLatch startSignal = new CountDownLatch(1);
4 CountDownLatch doneSignal = new CountDownLatch(3000);
5 for (int i = 0; i < 3000; i++) {
6 new Thread(new Worker(startSignal,doneSignal)).start();
7 }
8
9 System.out.println("准备。。。");
10 long beginTime = System.currentTimeMillis();
11 startSignal.countDown();
12 System.out.println("线程开始执行");
13 doneSignal.await();
14 long endTime = System.currentTimeMillis();
15 System.out.println("线程执行结束:"+(endTime-beginTime));
16}
17
18//核心工作类
19class Worker implements Runnable {
20 private final CountDownLatch startSignal;
21 private final CountDownLatch doneSignal;
22 Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
23 this.startSignal = startSignal;
24 this.doneSignal = doneSignal;
25 }
26 public void run() {
27 try {
28 startSignal.await();
29 doWork();
30 doneSignal.countDown();
31 } catch (InterruptedException ex) {} // return;
32 }
33
34 void doWork() {
35 System.out.println(Thread.currentThread().getName());
36 studentService.queryStudent();
37 }
38}
39
同时开启1000写,测试结果:
从图中可以看出,c3p0的性能被完爆。druid的性能优于tomcat的写。
下面测试3000个并发读:
从图中可以看出,tomcat的连接池性能和c3p0的读取差不多,稍微好一点。druid的读性能稍微差。