Author: doogie
Date: Sun Jun 26 02:50:41 2011
New Revision: 1139699
URL:
http://svn.apache.org/viewvc?rev=1139699&view=revLog:
FEATURE: Add helper method to fetch the results of all futures in a
collection, into a new list.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java?rev=1139699&r1=1139698&r2=1139699&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java Sun Jun 26 02:50:41 2011
@@ -19,18 +19,27 @@
package org.ofbiz.base.concurrent;
import java.lang.management.ManagementFactory;
+import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import java.util.concurrent.Delayed;
import java.util.concurrent.DelayQueue;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import javolution.util.FastList;
+
import org.ofbiz.base.lang.SourceMonitored;
+import org.ofbiz.base.util.Debug;
@SourceMonitored
public final class ExecutionPool {
+ public static final String module = ExecutionPool.class.getName();
+
protected static class ExecutionPoolThreadFactory implements ThreadFactory {
private final ThreadGroup group;
private final String namePrefix;
@@ -89,6 +98,20 @@ public final class ExecutionPool {
return getExecutor(null, namePrefix, -2, true);
}
+ public static <F> List<F> getAllFutures(Collection<Future<F>> futureList) {
+ List<F> result = FastList.newInstance();
+ for (Future<F> future: futureList) {
+ try {
+ result.add(future.get());
+ } catch (ExecutionException e) {
+ Debug.logError(e, module);
+ } catch (InterruptedException e) {
+ Debug.logError(e, module);
+ }
+ }
+ return result;
+ }
+
public static void addPulse(Pulse pulse) {
delayQueue.put(pulse);
}