/** * @return Returns a new {@link ThreadSnapshot} containing the currently active threads. JVM system threads are * filtered and not part of the thread snapshot. * @see #snapshot(boolean) */ public static ThreadSnapshot snapshot() { return snapshot(true); }
/** * This method checks if a thread should be processed by thread cleaning features. * * @param thread * The thread to check * @param threadSnapshot * Threads recorded by a thread snapshot are ignored by this method. * @param noProcessThreads * The threads to be ignored. * @return Returns <code>true</code> if the thread should be processed by thread cleaning features or * <code>false</code> if the thread should not be processed either because it is a JVM system thread or the * thread is contained by the <tt>noProcessThreads</tt> list. */ public static boolean processThread(Thread thread, ThreadSnapshot threadSnapshot, List<Thread> noProcessThreads) { // schuettec - 25.04.2017 : Ignore Daemon Threads because they will terminate if no other thread lives if (thread.isDaemon()) { return false; } ThreadGroup threadGroup = thread.getThreadGroup(); // Filter the shutdown thread and other java system threads if (noProcessThreads.contains(thread) || thread.getName() .equals("DestroyJavaVM") || (threadGroup != null && STATIC_THREADGROUP_FILTER.contains(threadGroup.getName())) || isStaticFilteredThreadName(thread.getName())) { return false; } else if (threadSnapshot != null && threadSnapshot.contains(thread)) { return false; } else { return true; } }
/** * @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); }
/** * @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. * @return Returns a new {@link ThreadSnapshot} containing the currently active threads. */ public static ThreadSnapshot snapshot(boolean filterJVMThreads) { return snapshot(filterJVMThreads, null); }
threadSnapshot = ThreadSnapshot.snapshot();