You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/01/02 10:59:35 UTC

[GitHub] [zookeeper] maoling commented on a change in pull request #1199: ZOOKEEPER-3671: Use ThreadLocalConcurrent to Replace Random and Math.…

maoling commented on a change in pull request #1199: ZOOKEEPER-3671: Use ThreadLocalConcurrent to Replace Random and Math.…
URL: https://github.com/apache/zookeeper/pull/1199#discussion_r362436037
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/watch/WatcherCleaner.java
 ##########
 @@ -133,7 +132,7 @@ public void run() {
                     // same time in the quorum
                     if (!stopped && deadWatchers.size() < watcherCleanThreshold) {
                         int maxWaitMs = (watcherCleanIntervalInSeconds
-                                         + r.nextInt(watcherCleanIntervalInSeconds / 2 + 1)) * 1000;
+                                         + ThreadLocalRandom.current().nextInt(watcherCleanIntervalInSeconds / 2 + 1)) * 1000;
 
 Review comment:
   - I also found `BlueThrottle` `ZooKeeperServer` still have the old `Random`, they also needs to change to `ThreadLocalRandom.current()`?
   - Please add a description about why needs this change? e.g. 
   `ThreadLocalRandom.current() is thread-safe and have a better performance than the old Random to avoid the Race Condition of CAS by multiple-threads
   `

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services