浏览代码

ZOOKEEPER-4204: Remove unnecessary creation of thousands of thread in…

…stances to prevent RequestPathMetricsCollectorTest.testMultiThreadPerf occasional failures

Author: Amichai Rothman <amichai@apache.org>

Reviewers: Michael Han <hanm@apache.org>, Damien Diederen <ddiederen@apache.org>

Closes #1598 from amichair/ZOOKEEPER-4204
Amichai Rothman 3 年之前
父节点
当前提交
7a368b4b19

+ 8 - 8
zookeeper-server/src/test/java/org/apache/zookeeper/server/util/RequestPathMetricsCollectorTest.java

@@ -421,23 +421,23 @@ public class RequestPathMetricsCollectorTest {
         ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
         ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
         //call 100k get Data
         //call 100k get Data
         for (int i = 0; i < 100000; i++) {
         for (int i = 0; i < 100000; i++) {
-            executor.submit(new Thread(() -> requestPathMetricsCollector.registerRequest(getData, "/path1/path2/path"
-                                                                                                          + rand.nextInt(10))));
+            executor.submit(
+                () -> requestPathMetricsCollector.registerRequest(getData, "/path1/path2/path" + rand.nextInt(10)));
         }
         }
         //5K create
         //5K create
         for (int i = 0; i < 5000; i++) {
         for (int i = 0; i < 5000; i++) {
-            executor.submit(new Thread(() -> requestPathMetricsCollector.registerRequest(create2, "/path1/path2/path"
-                                                                                                          + rand.nextInt(10))));
+            executor.submit(
+                () -> requestPathMetricsCollector.registerRequest(create2, "/path1/path2/path" + rand.nextInt(10)));
         }
         }
         //5K delete
         //5K delete
         for (int i = 0; i < 5000; i++) {
         for (int i = 0; i < 5000; i++) {
-            executor.submit(new Thread(() -> requestPathMetricsCollector.registerRequest(delete, "/path1/path2/path"
-                                                                                                         + rand.nextInt(10))));
+            executor.submit(
+                () -> requestPathMetricsCollector.registerRequest(delete, "/path1/path2/path" + rand.nextInt(10)));
         }
         }
         //40K getChildren
         //40K getChildren
         for (int i = 0; i < 40000; i++) {
         for (int i = 0; i < 40000; i++) {
-            executor.submit(new Thread(() -> requestPathMetricsCollector.registerRequest(getChildren, "/path1/path2/path"
-                                                                                                              + rand.nextInt(10))));
+            executor.submit(
+                () -> requestPathMetricsCollector.registerRequest(getChildren, "/path1/path2/path" + rand.nextInt(10)));
         }
         }
         executor.shutdown();
         executor.shutdown();
         //wait for at most 10 mill seconds
         //wait for at most 10 mill seconds