You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2014/05/17 15:19:50 UTC
svn commit: r1595473 -
/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/Pool.java
Author: rmannibucau
Date: Sat May 17 13:19:50 2014
New Revision: 1595473
URL: http://svn.apache.org/r1595473
Log:
revert for Thiago, shouldn't have changed anything excepted under contention where it would have added surely more locks ;) + fixing compilation error in ejbd module
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=1595473&r1=1595472&r2=1595473&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 Sat May 17 13:19:50 2014
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.openejb.util;
import org.apache.openejb.core.ParentClassLoaderFinder;
@@ -25,6 +24,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.NoSuchElementException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
@@ -105,7 +105,7 @@ public class Pool<T> {
greater("MaxAge", maxAge, "IdleTimeout", idleTimeout);
}
this.executor = executor != null ? executor : createExecutor();
- this.supplier = supplier != null ? supplier : new NoSupplier<T>();
+ this.supplier = supplier != null ? supplier : new NoSupplier();
this.available = strict ? new Semaphore(max) : new Overdraft(max);
this.minimum = new Semaphore(min);
this.instances = new Semaphore(max);
@@ -202,22 +202,30 @@ public class Pool<T> {
throw new TimeoutException("Waited " + timeout + " " + unit);
}
- synchronized (pool) {
- while (!pool.isEmpty()) {
- final Entry entry = pool.removeFirst();
- final Pool<T>.Entry.Instance instance = entry.soft.get();
- if (instance != null) {
- final boolean notBusy = entry.active.compareAndSet(null, instance);
- if (notBusy) {
- return entry;
- }
- } else {
- // the SoftReference was garbage collected
- instances.release();
+ Entry entry;
+ do {
+ synchronized (pool) {
+ try {
+ entry = pool.removeFirst();
+ } catch (final NoSuchElementException e) {
+ return null;
}
}
- }
- return null;
+
+ final Pool<T>.Entry.Instance instance = entry.soft.get();
+
+ if (instance != null) {
+
+ final boolean notBusy = entry.active.compareAndSet(null, instance);
+
+ if (notBusy) {
+ return entry;
+ }
+ } else {
+ // the SoftReference was garbage collected
+ instances.release();
+ }
+ } while (true);
}
/**
@@ -867,13 +875,13 @@ public class Pool<T> {
}
- private static class NoSupplier<T> implements Supplier<T> {
+ private static class NoSupplier implements Supplier {
@Override
public void discard(final Object o, final Event reason) {
}
@Override
- public T create() {
+ public Object create() {
return null;
}
}