public class ThreadBurstExecutorService
extends java.lang.Object
This class is similar to ExecutorService,
but it synchronizes the actual execution of all threads.
Note that the simple creation and starting of threads does not guarantee
that these threads run after Thread.start() returns.
Therefore this class does not support methods such as Executor.execute(Runnable)
which execute one Runnable in one thread independently of the other threads that it runs.
An instance is good for only one burst of threads, otherwise IllegalStateException will be thrown.
| Constructor and Description |
|---|
ThreadBurstExecutorService(java.util.concurrent.ThreadFactory threadFactory) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
executeAllAndWait(long timeout,
java.util.concurrent.TimeUnit unit)
Unleashes all submitted (and therefore already started) threads at the same time.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task,
long awaitExecutionTimeout,
java.util.concurrent.TimeUnit unit)
Submits a task and waits until the thread for this task has started (without yet executing the task!).
|
java.util.concurrent.Future<java.lang.Void> |
submit(java.lang.Runnable task,
long awaitExecutionTimeout,
java.util.concurrent.TimeUnit unit)
Variant of
submit(Callable, long, TimeUnit) which gives the task as a Runnable. |
boolean |
terminateAllAndWait(long timeout,
java.util.concurrent.TimeUnit unit)
Attempts to stop all running threads, waiting no longer than the given
timeout. |
public ThreadBurstExecutorService(java.util.concurrent.ThreadFactory threadFactory)
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task,
long awaitExecutionTimeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
executeAllAndWait(long, TimeUnit) is called
or the awaitExecutionTimeout occurs.task - The task that should be executed when executeAllAndWait(long, TimeUnit) is called.awaitExecutionTimeout - This timeout is used twice: (a) to wait for the thread to be created and started,
and to wait for the user to call executeAllAndWait(long, TimeUnit).java.lang.InterruptedException - If waiting for the thread to be created and started is interrupted.java.lang.IllegalStateException - if executeAllAndWait(long, TimeUnit) was called already.public java.util.concurrent.Future<java.lang.Void> submit(java.lang.Runnable task,
long awaitExecutionTimeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
submit(Callable, long, TimeUnit) which gives the task as a Runnable.
This does not allow to pass return values or exceptions from the thread to the caller,
but may be more customary to use.java.lang.InterruptedExceptionpublic boolean executeAllAndWait(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout occurs.
This method must only be called once for a given instance of ThreadBurstExecutor.
java.lang.IllegalStateException - if executeAllAndWait(long, TimeUnit) was called already.java.lang.InterruptedException - If waiting for the tasks to finish was interrupted.public boolean terminateAllAndWait(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout.
This method can be called either before executeAllAndWait(long, java.util.concurrent.TimeUnit) to stop the threads
that block on the thread gate to open, or afterwards to stop running tasks.
There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. This
implementation cancels tasks via Thread.interrupt(), so any task that fails to respond to interrupts may
never terminate.
timeout - unit - time unitjava.lang.InterruptedException