List<Thread> threadList = strList.stream()
.filter(StringUtils::isNotBlank)
.map(e -> new Thread(() ->
termService.getResult(e,startDate, endDate)))
.collect(Collectors.toList());
threadList.forEach(Thread::start);
threadList.forEach(t -> {
try {
t.join();
} catch (InterruptedException e) {
throw new CommonException("多线程查询时出错", e);
}
});
strList 的size() 决定启动的线程数,strList中的每个元素都作为参数e传入termService的getResult方法中,可以在getResult方法中将数据库的查询结果放入缓存,方便后续使用。