Java tutorial
//package com.java2s; public class Main { /** * Wait for all threads with the specified name to finish, i.e. to not appear in the * list of running threads any more. * * @param name * * @throws InterruptedException * @author dominik.stadler */ public static void waitForThreadToFinish(final String name) throws InterruptedException { int count = Thread.currentThread().getThreadGroup().activeCount(); Thread[] threads = new Thread[count]; Thread.currentThread().getThreadGroup().enumerate(threads); for (Thread t : threads) { if (t != null && name.equals(t.getName())) { t.join(); } } } }