- Reference: juejin. Cn/post / 693568…
- Reference: blog.csdn.net/weixin_4586…
- Reference: hutool. Mydoc. IO / # text_32155…
/** Thread pool – Executors */
List<EInvoiceMain> eInvoiceMainList = Collections.synchronizedList(new ArrayList<>()); final ExecutorService executorService = Executors.newFixedThreadPool(paths.size()); for (String url : paths) { executorService.execute(new Runnable(){ } } executorService.shutdown(); if(! executorService.isTerminated()){ while (true) { if (executorService.isTerminated()) { break; } } } if (CollUtil.isNotEmpty(eInvoiceMainList)) { updateEntityInfo(eInvoiceMainList); } return eInvoiceMainList;Copy the code
/** thread pool – CountDownLatch */
List<EInvoiceMain> eInvoiceMainList = Collections.synchronizedList(new ArrayList<>()); final CountDownLatch downLatch = new CountDownLatch(paths.size()); For (String url: paths) {new Thread(new Runnable() {public void run() {-- sout("url"); CountDownLatch () */ downlatch.countdown (); } }).start(); } try { downLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } if (CollUtil.isNotEmpty(eInvoiceMainList)) { updateEntityInfo(eInvoiceMainList); } return eInvoiceMainList;Copy the code
/** thread pool -hutool -threadutil */
List<EInvoiceMain> eInvoiceMainList = Collections.synchronizedList(new ArrayList<>()); final ExecutorService executorService = ThreadUtil.newExecutor(paths.size()); Executorservice.execute (new Runnable() {public void run(){-- sout("url"); executorService.execute(new Runnable() {public void run(){-- sout("url"); }}); } executorService.shutdown(); if(! executorService.isTerminated()){ while (true) { if (executorService.isTerminated()) { break; } } } if (CollUtil.isNotEmpty(eInvoiceMainList)) { updateEntityInfo(eInvoiceMainList); } return eInvoiceMainList;Copy the code