Java tutorial
//package com.java2s; import java.util.concurrent.*; public class Main { /** * @param exec * @param checkInterval */ public static void checkBlockPoolCompleted(ThreadPoolExecutor exec, int checkInterval) { checkBlockPoolCompleted(exec, checkInterval, false); } /** * @param exec * @param checkInterval * @param shutdown */ public static void checkBlockPoolCompleted(ThreadPoolExecutor exec, int checkInterval, boolean shutdown) { while (true) { int activite = exec.getActiveCount(); waitFor(checkInterval); if (activite == 0) { break; } } if (shutdown) { exec.shutdown(); try { exec.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } public static void waitFor(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }