ThreadUtil { static public Thread[] getAllThreads() { final ThreadGroup root = getRootThreadGroup(); final ThreadMXBean thbean = ManagementFactory.getThreadMXBean(); int nAlloc = thbean.getThreadCount(); int n = 0; Thread[] threads; do { nAlloc *= 2; threads = new Thread[nAlloc]; n = root.enumerate(threads, true); } while (n == nAlloc); return java.util.Arrays.copyOf(threads, n); }  static ThreadGroup getRootThreadGroup(); static Thread[] getAllThreads(); static Thread getThread(final long id); static Thread[] getAllThreadsMatching(final String regex);  }
@Test public void getAllThreads() { Thread[] allThreads = ThreadUtil.getAllThreads(); Assert.assertEquals(true, allThreads.length >= 4); }