THUMarkLau commented on code in PR #9743:
URL: https://github.com/apache/iotdb/pull/9743#discussion_r1180181061


##########
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/jvm/JvmThreadMetrics.java:
##########
@@ -85,9 +93,25 @@ public void unbindFrom(AbstractMetricService metricService) {
 
   // VisibleForTesting
   static long getThreadStateCount(ThreadMXBean threadBean, Thread.State state) 
{
-    return 
Arrays.stream(threadBean.getThreadInfo(threadBean.getAllThreadIds()))
-        .filter(threadInfo -> threadInfo != null && 
threadInfo.getThreadState() == state)
-        .count();
+    checkAndUpdate(threadBean);
+    return threadStateCountMap.getOrDefault(state, 0);
+  }
+
+  private static void checkAndUpdate(ThreadMXBean threadBean) {
+    if (System.currentTimeMillis() - lastUpdateTime < UPDATE_INTERVAL) {
+      return;
+    }
+    lastUpdateTime = System.currentTimeMillis();
+    threadStateCountMap.clear();
+    List<ThreadInfo> infoList =
+        Arrays.asList(threadBean.getThreadInfo(threadBean.getAllThreadIds()));
+    infoList.forEach(
+        info -> {
+          if (info != null) {
+            Thread.State state = info.getThreadState();
+            threadStateCountMap.put(state, 
threadStateCountMap.getOrDefault(state, 0) + 1);

Review Comment:
   resolve



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