public void test() { List<String> tasks = new ArrayList<>(); int i = 0; do { tasks.add("" + i); } while (i++ < 100); try { CountDownLatch latch = new CountDownLatch(tasks.size()); tasks.stream().forEach((loanTask) -> { executor.submit(() -> { Thread.currentThread().setName("LoanJob-" + UUID.randomUUID().toString()); handleData(loanTask); }); latch.countDown(); }); latch.await(); } catch (Exception e) { e.printStackTrace(); } System.err.println("end"); } public void handleData(String i) { System.err.println("H: " + i); int c = 1 / 0; System.err.println(c); }