public class InterruptibleMulticoreWrapper<I,O> extends MulticoreWrapper<I,O>
Constructor and Description |
---|
InterruptibleMulticoreWrapper(int numThreads,
ThreadsafeProcessor<I,O> processor,
boolean orderResults,
long timeout)
Create an interruptible thread pool for multithreaded processing.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
After a shutdown request, await for the final termination of all
threads.
|
protected java.util.concurrent.ThreadPoolExecutor |
buildThreadPool(int nThreads) |
protected java.lang.Integer |
getProcessor()
Returns the next available thread id.
|
java.util.List<I> |
joinWithTimeout()
Shuts down the thread pool, returns when finished.
|
public InterruptibleMulticoreWrapper(int numThreads, ThreadsafeProcessor<I,O> processor, boolean orderResults, long timeout)
numThreads
- If less than or equal to 0, then automatically determine the number
of threads. Otherwise, the size of the underlying threadpool.processor
- The processor (factory) for what will be run on data.orderResults
- If true, return results in the order submitted. Otherwise, return results
as they become available.timeout
- If timeout
is a positive number, the threadpool attempts to allow jobs to run
for only this many milliseconds, but it depends on threads being Interruptible to succeed.
If zero or negative, thread runtime is unlimited.protected java.util.concurrent.ThreadPoolExecutor buildThreadPool(int nThreads)
buildThreadPool
in class MulticoreWrapper<I,O>
protected java.lang.Integer getProcessor()
MulticoreWrapper
public java.util.List<I> joinWithTimeout()
If timeout
is positive, then join
waits at
most timeout
milliseconds for threads to finish. If
any fail to finish in that time, the threadpool is shutdownNow.
After that, join
continues to wait for the
interrupted threads to finish, so if job do not obey
interruptions, they can continue indefinitely regardless of the
timeout.
timeout
was reached, or an empty list if that did not
happen.public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
java.lang.InterruptedException