BELUGABEHR commented on a change in pull request #876: ZOOKEEPER-3020: Review 
of SyncRequestProcessor
URL: https://github.com/apache/zookeeper/pull/876#discussion_r273283081
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/SyncRequestProcessor.java
 ##########
 @@ -102,103 +108,96 @@ public void run() {
 
             // we do this in an attempt to ensure that not all of the servers
             // in the ensemble take a snapshot at the same time
-            int randRoll = r.nextInt(snapCount/2);
+            int randRoll = ThreadLocalRandom.current().nextInt(snapCount / 2, 
snapCount);
             while (true) {
-                Request si = null;
-                if (toFlush.isEmpty()) {
+                Request si = queuedRequests.poll();
 
 Review comment:
   > Retrieves and removes the head of this queue, waiting if necessary until 
an element becomes available.
   
   
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html#take()
   
   The only way a 'null' could become available here is if a 'null' value is 
inserted into the collection.  However, that is prevented on line 212.
   
   I believe this is a good improvement because previously it was always 
checking 'isEmpty' to make a decision about how to interact with the 
'queuedRequests' queue.  I have removed that condition and it will just go 
ahead and try to pull something from the queue.

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


With regards,
Apache Git Services

Reply via email to