CountDownLatch降低数据库查询压力(缺点:增大内存消耗)

//线程池初始化
int thread = 3;
ExecutorService executorService = Executors.newFixedThreadPool(thread);
final CountDownLatch countDownLatch = new CountDownLatch(thread);
//线程执行
executorService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
 AMapper.select();
countDownLatch.countDown();
return null;
}
});
executorService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
 BMapper.select();
countDownLatch.countDown();
return null;
}
});
executorService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
 CMapper.select();
countDownLatch.countDown();
return null;
}
});
try {
countDownLatch.await();
   //组装数据
} catch (InterruptedException e) {
e.printStackTrace();
}
posted @ 2021-12-23 10:59  懂得归零  阅读(223)  评论(0)    收藏  举报