kaisun2000 commented on a change in pull request #1452:
URL: https://github.com/apache/helix/pull/1452#discussion_r502012664
##########
File path: helix-core/src/test/java/org/apache/helix/ThreadLeakageChecker.java
##########
@@ -0,0 +1,181 @@
+package org.apache.helix;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import org.apache.helix.common.ZkTestBase;
+
+
+public class ThreadLeakageChecker {
+ private static ThreadGroup getRootThreadGroup() {
+ ThreadGroup candidate = Thread.currentThread().getThreadGroup();
+ while (candidate.getParent() != null) {
+ candidate = candidate.getParent();
+ }
+ return candidate;
+ }
+
+ private static List<Thread> getAllThreads() {
+ ThreadGroup rootThreadGroup = getRootThreadGroup();
+ Thread[] threads = new Thread[32];
+ int count = rootThreadGroup.enumerate(threads);
+ while (count == threads.length) {
+ threads = new Thread[threads.length * 2];
+ count = rootThreadGroup.enumerate(threads);
+ }
+ return Arrays.asList(Arrays.copyOf(threads, count));
+ }
+
+ private static final String[] ZkServerThrdPattern =
+ {"SessionTracker", "NIOServerCxn", "SyncThread:", "ProcessThread"};
+ private static final String[] ZkSessionThrdPattern =
+ new String[]{"ZkClient-EventThread", "ZkClient-AsyncCallback",
"-EventThread", "-SendThread"};
+ private static final String[] ForkJoinThrdPattern = new
String[]{"ForkJoinPool"};
+ private static final String[] TimerThrdPattern = new String[]{"time"};
+ private static final String[] TaskStateModelThrdPattern = new
String[]{"TaskStateModel"};
+
+ private static enum ThreadCategory {
Review comment:
Good question. The two threshold are mostly empirical.
ZkServer, our version has only 4 threads now. In case later version use
more. I set the limit to 100. The reasoning is that these ZkServer threads are
not deemed as leaking no matter how much they have.
ZkSession is the ZkClient and native Zookeeper client we have. ZkTestBase
has 12 at starting up time. Thus, if there is more than that, it is the test
code leaking ZkClient.
ForkJoin is created by using parallel stream or whatever Java features. This
is out of our control, similar to ZkServer. Let me change the _limit to 100
while keep a small _warningLimit. (Will make change for this one).
Timer should not happen. Setting limit to 2 not 0 mostly because even when
you cancel the timer thread, it may take some not deterministic time for it to
go away. So give it some slack here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]