Author: andygumbrecht
Date: Sun Jul  6 16:59:32 2014
New Revision: 1608246

URL: http://svn.apache.org/r1608246
Log:
Less aggressive loops

Modified:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java?rev=1608246&r1=1608245&r2=1608246&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
 Sun Jul  6 16:59:32 2014
@@ -99,6 +99,7 @@ public class Pool<T> {
         this(max, min, strict, 0, 0, 0, null, null, false, -1, false, false);
     }
 
+    @SuppressWarnings("unchecked")
     public Pool(final int max, final int min, final boolean strict, final long 
maxAge, final long idleTimeout, long sweepInterval, final Executor executor, 
final Supplier<T> supplier, final boolean replaceAged, final double 
maxAgeOffset, final boolean garbageCollection, final boolean replaceFlushed) {
         if (min > max) {
             greater("max", max, "min", min);
@@ -291,7 +292,7 @@ public class Pool<T> {
      * Failure to do so will increase the max pool size by one.
      *
      * @param obj    object to push onto the pool
-     * @param offset
+     * @param offset long
      * @return false if the pool max size was exceeded
      */
     private boolean push(final T obj, final long offset) {
@@ -420,6 +421,12 @@ 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()) {
+            Thread.yield();
+        }
+        while (minimum.tryAcquire()) {
+            Thread.yield();
+        }
         instances.drainPermits();
         minimum.drainPermits();
 
@@ -436,6 +443,9 @@ public class Pool<T> {
 
         // Drain all leases
         if (!(available instanceof Overdraft)) {
+            while (available.tryAcquire()) {
+                Thread.yield();
+            }
             available.drainPermits();
         }
 
@@ -1187,6 +1197,11 @@ public class Pool<T> {
             super(referent);
             this.hard = referent;
         }
+
+        @SuppressWarnings("UnusedDeclaration")
+        public T getHard() {
+            return hard;
+        }
     }
 
     static class SchedulerThreadFactory implements ThreadFactory {


Reply via email to