cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1360406 - /cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
Date Wed, 11 Jul 2012 21:15:48 GMT
Author: dkulp
Date: Wed Jul 11 21:15:48 2012
New Revision: 1360406

URL: http://svn.apache.org/viewvc?rev=1360406&view=rev
Log:
If another thread is working on adding threads, just return and let it
handle it.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java?rev=1360406&r1=1360405&r2=1360406&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java Wed Jul
11 21:15:48 2012
@@ -71,7 +71,7 @@ public class AutomaticWorkQueueImpl impl
     
     AWQThreadFactory threadFactory;
     ReentrantLock mainLock;
-    
+    final ReentrantLock addThreadLock = new ReentrantLock();
     
     DelayQueue<DelayedTaskWrapper> delayQueue;
     WatchDog watchDog;
@@ -440,20 +440,25 @@ public class AutomaticWorkQueueImpl impl
         ex.execute(r);
         if (addWorkerMethod != null 
             && !ex.getQueue().isEmpty() 
-            && this.approxThreadCount < highWaterMark) {
-            mainLock.lock();
+            && this.approxThreadCount < highWaterMark
+            && addThreadLock.tryLock()) {
             try {
-                int ps = this.getPoolSize();
-                int sz = executor.getQueue().size();
-                int sz2 = this.getActiveCount();
-                
-                if ((sz + sz2) > ps) {
-                    ReflectionUtil.setAccessible(addWorkerMethod).invoke(executor, addWorkerArgs);
+                mainLock.lock();
+                try {
+                    int ps = this.getPoolSize();
+                    int sz = executor.getQueue().size();
+                    int sz2 = this.getActiveCount();
+                    
+                    if ((sz + sz2) > ps) {
+                        ReflectionUtil.setAccessible(addWorkerMethod).invoke(executor, addWorkerArgs);
+                    }
+                } catch (Exception exc) {
+                    //ignore
+                } finally {
+                    mainLock.unlock();
                 }
-            } catch (Exception exc) {
-                //ignore
             } finally {
-                mainLock.unlock();
+                addThreadLock.unlock();
             }
         }
     }



Mime
View raw message