You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/12/25 22:51:03 UTC

[cxf] branch 3.4.x-fixes updated: Attempt to fix flaky org.apache.cxf.workqueue.AutomaticWorkQueueTest.testEnqueueImmediate test case

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.4.x-fixes by this push:
     new a8d2299  Attempt to fix flaky org.apache.cxf.workqueue.AutomaticWorkQueueTest.testEnqueueImmediate test case
a8d2299 is described below

commit a8d22993fadd58ea05467a34e7e2efce20593bbc
Author: reta <dr...@gmail.com>
AuthorDate: Fri Dec 25 14:55:23 2020 -0500

    Attempt to fix flaky org.apache.cxf.workqueue.AutomaticWorkQueueTest.testEnqueueImmediate test case
    
    (cherry picked from commit a8de3c584869aeec3a1427fb53a4b7f843c892d4)
---
 .../java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java     | 8 ++++----
 .../java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java     | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java b/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
index 252386a..5f8a0ce 100644
--- a/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
+++ b/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
@@ -63,7 +63,7 @@ public class AutomaticWorkQueueImpl implements AutomaticWorkQueue {
     int lowWaterMark;
     int highWaterMark;
     long dequeueTimeout;
-    volatile int approxThreadCount;
+    AtomicInteger approxThreadCount = new AtomicInteger();
 
     ThreadPoolExecutor executor;
     Method addWorkerMethod;
@@ -340,11 +340,11 @@ public class AutomaticWorkQueueImpl implements AutomaticWorkQueue {
             }
             Runnable wrapped = new Runnable() {
                 public void run() {
-                    ++approxThreadCount;
+                    approxThreadCount.incrementAndGet();
                     try {
                         r.run();
                     } finally {
-                        --approxThreadCount;
+                        approxThreadCount.decrementAndGet();
                     }
                 }
             };
@@ -426,7 +426,7 @@ public class AutomaticWorkQueueImpl implements AutomaticWorkQueue {
         ex.execute(r);
         if (addWorkerMethod != null
             && !ex.getQueue().isEmpty()
-            && this.approxThreadCount < highWaterMark
+            && this.approxThreadCount.get() < highWaterMark
             && addThreadLock.tryLock()) {
             try {
                 mainLock.lock();
diff --git a/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java b/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
index 76d30fc..c13698c 100644
--- a/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
+++ b/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
@@ -191,7 +191,9 @@ public class AutomaticWorkQueueTest {
                 Thread.sleep(100L);
                 numRun = numRunning(workItems);
             }
+
             numRun = numRunning(workItems);
+            assertEquals(0, workqueue.getSize());
             assertEquals(DEFAULT_HIGH_WATER_MARK, numRun);
 
             for (int i = 0; i < DEFAULT_MAX_QUEUE_SIZE; i++) {