@Resource(name = "threadPoolExecutor")
private ExecutorService executorService;
CountDownLatch latch = new CountDownLatch(num);
this.threadDateTimeGetCurData(param);
latch.await();// 等待所有任务结束
LogUtils.logInfo("线程已全部结束");
public void threadDateTimeGetCurData(param) {
for (int i = 0; i < fileParam.size(); i++) {
int finalI = i;
executorService.execute(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
doSomThing();
} catch (Exception e) {
LogUtils.logError("数据异常" + fileParam.get(finalI), e);
} finally {
latch.countDown();
}
}
});
}
}