Ax1an commented on a change in pull request #7243:
URL: https://github.com/apache/skywalking/pull/7243#discussion_r663875013



##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/thread/ThreadProvider.java
##########
@@ -31,12 +32,58 @@
     }
 
     public Thread getThreadMetrics() {
+        int newStateThreadCount = 0;
+        int runnableStateThreadCount = 0;
+        int blockedStateThreadCount = 0;
+        int waitingStateThreadCount = 0;
+        int timedWaitingStateThreadCount = 0;
+        int terminatedStateThreadCount = 0;
+
+        ThreadInfo[] threadInfos = 
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 0);
+        if (threadInfos != null) {
+            for (ThreadInfo threadInfo : threadInfos) {
+                if (threadInfo != null) {
+                    switch (threadInfo.getThreadState()) {
+                        case NEW:
+                            newStateThreadCount++;
+                            break;
+                        case RUNNABLE:
+                            runnableStateThreadCount++;
+                            break;
+                        case BLOCKED:
+                            blockedStateThreadCount++;
+                            break;
+                        case WAITING:
+                            waitingStateThreadCount++;
+                            break;
+                        case TIMED_WAITING:
+                            timedWaitingStateThreadCount++;
+                            break;
+                        case TERMINATED:
+                            terminatedStateThreadCount++;
+                            break;
+                        default:
+                            break;
+                    }
+                } else {
+                    terminatedStateThreadCount++;
+                }

Review comment:
       The code as a whole looks good. However, there may be some inaccuracies 
in this place. I found that `getAllThreadIds()` and `getThreadInfo` method both 
return information about the active thread. However, when the thread is in the 
NEW and TERMINATED state, the `isAlive()` method will return false, that is, 
they are inactive. Therefore, in this way, we cannot correctly count the number 
of threads in the NEW and TERMINATED state.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to