You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/07/06 13:58:36 UTC

svn commit: r1608191 - in /tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src: main/java/org/apache/openejb/util/Pool.java test/java/org/apache/openejb/util/PoolTest.java

Author: andygumbrecht
Date: Sun Jul  6 11:58:36 2014
New Revision: 1608191

URL: http://svn.apache.org/r1608191
Log:
Flush and sweep before calling stop (which stops the sweeper executor!)

Modified:
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/util/PoolTest.java

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java?rev=1608191&r1=1608190&r2=1608191&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java Sun Jul  6 11:58:36 2014
@@ -28,6 +28,7 @@ import java.util.NoSuchElementException;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.ThreadFactory;
@@ -55,6 +56,7 @@ import static java.util.concurrent.TimeU
  *
  * @version $Rev$ $Date$
  */
+@SuppressWarnings("StatementWithEmptyBody")
 public class Pool<T> {
 
     private final LinkedList<Entry> pool = new LinkedList<Entry>();
@@ -123,7 +125,9 @@ public class Pool<T> {
     }
 
     public Pool start() {
-        if (this.scheduler.compareAndSet(null, Executors.newScheduledThreadPool(1, new SchedulerThreadFactory()))) {
+        final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1, new SchedulerThreadFactory());
+
+        if (this.scheduler.compareAndSet(null, scheduledExecutorService)) {
             this.scheduler.get().scheduleAtFixedRate(sweeper, 0, this.sweepInterval, MILLISECONDS);
         }
         return this;
@@ -417,23 +421,27 @@ public class Pool<T> {
     public boolean close(final long timeout, final TimeUnit unit) throws InterruptedException {
         // drain all keys so no new instances will be accepted into the pool
         while (instances.tryAcquire()) {
-            ; //NOPMD
+            //NOPMD
         }
         while (minimum.tryAcquire()) {
-            ; //NOPMD
+            //NOPMD
         }
 
-        // Stop the sweeper thread
-        stop();
-
         // flush and sweep
         flush();
-        sweeper.run();
+        try {
+            sweeper.run();
+        } catch (final RejectedExecutionException e) {
+            //Ignore
+        }
+
+        // Stop the sweeper thread
+        stop();
 
         // Drain all leases
         if (!(available instanceof Overdraft)) {
             while (available.tryAcquire()) {
-                ; //NOPMD
+                //NOPMD
             }
         }
 
@@ -964,7 +972,7 @@ public class Pool<T> {
         }
     }
 
-    @SuppressWarnings("PMD.UnusedPrivateField")
+    @SuppressWarnings({"PMD.UnusedPrivateField", "UnusedDeclaration"})
     @Managed
     private final class Stats {
 
@@ -1002,7 +1010,7 @@ public class Pool<T> {
         private final int maxSize;
 
         @Managed
-        private long idleTimeout;
+        private final long idleTimeout;
 
         private Stats(final int minSize, final int maxSize, final long idleTimeout) {
             this.minSize = minSize;
@@ -1046,6 +1054,7 @@ public class Pool<T> {
         }
     }
 
+    @SuppressWarnings("UnusedDeclaration")
     public static class Builder<T> {
 
         private int max = 10;
@@ -1106,8 +1115,7 @@ public class Pool<T> {
         /**
          * Alias for pool size
          *
-         * @param max
-         * @return
+         * @param max int
          */
         public void setPoolSize(final int max) {
             setMaxSize(max);

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/util/PoolTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/util/PoolTest.java?rev=1608191&r1=1608190&r2=1608191&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/util/PoolTest.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/util/PoolTest.java Sun Jul  6 11:58:36 2014
@@ -1367,7 +1367,7 @@ public class PoolTest extends TestCase {
 
         public static AtomicInteger instances = new AtomicInteger();
 
-        private int count;
+        private final int count;
         private final long created;
         private long accessed;
         private long discarded;