Package se.hb.jcp.util
Class FIFOParallelExecutor<E>
- java.lang.Object
-
- se.hb.jcp.util.FIFOParallelExecutor<E>
-
- Type Parameters:
E- the type of the result returned by the Callables.
public class FIFOParallelExecutor<E> extends java.lang.ObjectA FIFOParallelExecutor executes Callables in parallel and returns the results in the order the Callables were issued. The class does not implement the Java Executor interface despite its name.- Author:
- anders.gidenstam(at)hb.se
-
-
Constructor Summary
Constructors Constructor Description FIFOParallelExecutor(int parallelism, java.util.concurrent.ExecutorService executorService)Creates a FIFOParallelExecutor using the provided level of parallelism and the ExecutorService to execute the Callables.FIFOParallelExecutor(java.util.concurrent.BlockingQueue<java.util.concurrent.Future<E>> queue, java.util.concurrent.ExecutorService executorService)Creates a FIFOParallelExecutor using the provided BlockingQueue and the ExecutorService to execute the Callables.FIFOParallelExecutor(java.util.concurrent.ExecutorService executorService)Creates a FIFOParallelExecutor using the provided ExecutorService to execute the Callables.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsubmit(java.util.concurrent.Callable<E> e)Submits the Callable for execution.Etake()Returns the next result, blocking to await its arrival or completion if needed.
-
-
-
Constructor Detail
-
FIFOParallelExecutor
public FIFOParallelExecutor(java.util.concurrent.ExecutorService executorService)
Creates a FIFOParallelExecutor using the provided ExecutorService to execute the Callables.- Parameters:
executorService- the ExecutorService used to execute the Callables.
-
FIFOParallelExecutor
public FIFOParallelExecutor(int parallelism, java.util.concurrent.ExecutorService executorService)Creates a FIFOParallelExecutor using the provided level of parallelism and the ExecutorService to execute the Callables.- Parameters:
parallelism- the level of parallelism to use.executorService- the ExecutorService used to execute the Callables.
-
FIFOParallelExecutor
public FIFOParallelExecutor(java.util.concurrent.BlockingQueue<java.util.concurrent.Future<E>> queue, java.util.concurrent.ExecutorService executorService)
Creates a FIFOParallelExecutor using the provided BlockingQueue and the ExecutorService to execute the Callables.- Parameters:
queue- the blocking queue used to store the submitted Callables.executorService- the ExecutorService used to execute the Callables.
-
-
Method Detail
-
submit
public void submit(java.util.concurrent.Callable<E> e) throws java.lang.InterruptedException
Submits the Callable for execution. Blocks if the level of parallelism is exceeded.- Parameters:
e- a Callable<E> that is to be executed.- Throws:
java.lang.InterruptedException
-
take
public E take() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Returns the next result, blocking to await its arrival or completion if needed.- Returns:
- the next result from the submitted Callables.
- Throws:
java.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
-