killbill-memoizeit

util: fix race condition in PersistentQueueBase On shutdown,

2/1/2013 7:44:35 PM

Details

diff --git a/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java b/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
index 8e1f7bf..d3706bb 100644
--- a/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
+++ b/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
@@ -94,12 +94,8 @@ public abstract class PersistentQueueBase implements QueueLifecycle {
 
                     try {
                         while (true) {
-
-                            synchronized (thePersistentQ) {
-                                if (!isProcessingEvents) {
-                                    thePersistentQ.notify();
-                                    break;
-                                }
+                            if (!isProcessingEvents) {
+                                break;
                             }
 
                             try {
@@ -119,10 +115,10 @@ public abstract class PersistentQueueBase implements QueueLifecycle {
                     } catch (Throwable e) {
                         log.error(String.format("%s: Thread %s got an exception, exting... ", svcQName, Thread.currentThread().getName()), e);
                     } finally {
-
                         log.info(String.format("%s: Thread %s has exited", svcQName, Thread.currentThread().getName()));
                         synchronized (thePersistentQ) {
                             curActiveThreads--;
+                            thePersistentQ.notify();
                         }
                     }
                 }