franz1981 commented on a change in pull request #44:
URL: https://github.com/apache/qpid-jms/pull/44#discussion_r737530088



##########
File path: qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
##########
@@ -194,6 +193,42 @@ public void onPendingFailure(ProviderException cause) {
         }
     }
 
+    private void processCompletions() {
+        do {
+            if (!completionThread.compareAndSet(null, Thread.currentThread())) 
{
+                return;
+            }
+            try {
+                Runnable completionTask;
+                while ((completionTask = completionTasks.poll()) != null) {
+                    try {
+                        completionTask.run();
+                    } catch (Throwable t) {
+                        LOG.debug("errored on processCompletions duty cycle", 
t);
+                    }
+                }
+            } finally {
+                completionThread.set(null);
+            }
+        } while (!completionTasks.isEmpty());

Review comment:
       isEmpty can be called by *any* threads concurrently without 
restrictions, but `poll` has to be called in a single threaded fashion ie one 
thread "at time" or just the same thread
   
   The use case of isEmpty is exactly for this type of duty cycle loop (very 
common in Akka actors mailboxes, that use JCTools), which can be executed by 
any thread, but serially, and is used to detect if it worth to "continue" 
draining the mailbox.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to