try { List<String> fileList = getLocalCacheFiles(); final CountDownLatch countDownLatch = new CountDownLatch(fileList.size()); for (String file : fileList) { new Thread(()->{ try { processZipFile(file); } catch (Exception e) { e.printStackTrace(); }finally { countDownLatch.countDown(); } }).start(); } try { countDownLatch.await(); } catch (Exception e) { e.printStackTrace(); logger.error("processZipFile线程"+e.getMessage()); } } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); }
Java 中使用多线程时有时会需要等多线程执行的代码执行完的后续操作
最新推荐文章于 2022-08-26 23:57:54 发布