/** * @param filterJVMThreads * If <code>true</code> the JVM system threads are not part of the created snapshot. If <code>false</code> * also JVM system threads will be recorded by the thread snapshot. * @param filterCondition * (Optional) An optional filter condition * @return Returns a new {@link ThreadSnapshot} containing the currently active threads. */ public static ThreadSnapshot snapshot(boolean filterJVMThreads, ThreadFilter filterCondition) { Set<Integer> hashCodes = new HashSet<>(); Set<Thread> allThreads = ThreadCleaning.getAllThreads(); for (Thread t : allThreads) { boolean add = true; if (filterJVMThreads) { add = ThreadCleaning.processThread(t, null); } if (add) { if (filterCondition != null) { add = filterCondition.accept(t); } if (add) { hashCodes.add(System.identityHashCode(t)); } } } return new ThreadSnapshot(hashCodes); }