多线程测试执行时间
final HelloService helloService = (HelloService)context.getBean("helloService"); // get service invocation proxy
ExecutorService executorServicePool = Executors.newFixedThreadPool(200);
final int size = 10000;
final CountDownLatch cdl = new CountDownLatch(size);
long begin = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
executorServicePool.execute(new Runnable() {
@Override
public void run() {
try {
String hello = helloService.hello("aa"); // do invoke!
cdl.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
cdl.await();//等待所有任务处理完
long time = System.currentTimeMillis() - begin;
System.out.println("耗时:" + time);