public static Map<String ,List<Map<String, Object>>> getMaps(List<String> sqlKeys) throws InterruptedException, ExecutionException{
if(CollectionUtils.isEmpty(sqlKeys)) {
return null;
}
Map<String ,List<Map<String, Object>>> map = new HashMap<String ,List<Map<String, Object>>>();
ExecutorService executorService = Executors.newFixedThreadPool(2);
final CountDownLatch countDownLatch = new CountDownLatch(2);
Future<List<Map<String, Object>>> outputDatas = executorService.submit(new Callable<List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> call() throws Exception {
try {
return new HanaJdbc().querySQLForList(PropertyPlaceholderUtil.getProperty("COMPANY.CODE"), null, false);
}finally {
countDownLatch.countDown();
}
}
});
Future<List<Map<String, Object>>> outputDatas2 = executorService.submit(new Callable<List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> call() throws Exception {
try {
return new HanaJdbc().querySQLForList(PropertyPlaceholderUtil.getProperty("UNIT.CODE"), null, false);
}finally {
countDownLatch.countDown();
}
}
});
countDownLatch.await();
map.put("COMPANY.CODE", outputDatas.get());
map.put("UNIT.CODE", outputDatas2.get());
return map;
}
1.如果outputDatas和outputDatas2的执行时间分别是2秒的/3秒,那么这个方法的最终执行时间是3秒多一点点,
2.如果两者之间没有任何数据上的前置作用,那么可以这样写,性能可以大幅提升。