如果是需要频繁调用,不建议使用此方案的多线程,建议使用线程池,可以重复调用
public Map<String, Object> tow() throws InterruptedException {
Map<String, Object> map = new HashMap<>();
ExecutorService executor = Executors.newFixedThreadPool(2);//做2个线程
executor.submit(() -> {
map.put("a", this.baseMapper.selectList(null));//操作1
});
executor.submit(() -> {
map.put("b", this.baseMapper.selectList(null));//操作2
});
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES);//设置等待时间最大(即为不设置)
return map;
}