void (List<Thread> threads, int timeoutMillis) { for (Thread thread : threads) { try { thread.join(timeoutMillis); if (thread.isAlive()) { throw new RuntimeException("Failed to join thread in " + timeoutMillis + " ms."); } } catch (InterruptedException e) { throw new RuntimeException(e); } } }