Classes | |
class | InterceptingCallable< V > |
Public Member Functions | |
ThreadBurstExecutorService (ThreadFactory threadFactory) | |
Future< Void > | submit (final Runnable task, long awaitExecutionTimeout, TimeUnit unit) throws InterruptedException |
boolean | executeAllAndWait (long timeout, TimeUnit unit) throws InterruptedException |
boolean | terminateAllAndWait (long timeout, TimeUnit unit) throws InterruptedException |
Package Functions | |
public< T > Future< T > | submit (Callable< T > task, long awaitExecutionTimeout, TimeUnit unit) throws InterruptedException |
Helper class that allows tests (but also other code) to be executed concurrently, in an attempt to "bombard" a tested class with parallel calls, all arriving in the smallest possible time window.
This class is similar to java.util.concurrent.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 ExecutorService#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.
alma.acs.concurrent.ThreadBurstExecutorService.ThreadBurstExecutorService | ( | ThreadFactory | threadFactory | ) |
boolean alma.acs.concurrent.ThreadBurstExecutorService.executeAllAndWait | ( | long | timeout, | |
TimeUnit | unit | |||
) | throws InterruptedException |
Unleashes all submitted (and therefore already started) threads at the same time. Then waits until all tasks finish, or until the given timeout
occurs.
This method must only be called once for a given instance of ThreadBurstExecutor.
IllegalStateException | if executeAllAndWait(long, TimeUnit) was called already. | |
InterruptedException | If waiting for the tasks to finish was interrupted. |
Future<Void> alma.acs.concurrent.ThreadBurstExecutorService.submit | ( | final Runnable | task, | |
long | awaitExecutionTimeout, | |||
TimeUnit | unit | |||
) | throws InterruptedException |
Variant of 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.
References alma.acs.concurrent.ThreadBurstExecutorService.submit().
public<T> Future<T> alma.acs.concurrent.ThreadBurstExecutorService.submit | ( | Callable< T > | task, | |
long | awaitExecutionTimeout, | |||
TimeUnit | unit | |||
) | throws InterruptedException [package] |
Submits a task and waits until the thread for this task has started (without yet executing the task!). Then this thread will block until 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). |
InterruptedException | If waiting for the thread to be created and started is interrupted. | |
IllegalStateException | if executeAllAndWait(long, TimeUnit) was called already. |
Referenced by alma.acs.concurrent.ThreadBurstExecutorService.submit().
boolean alma.acs.concurrent.ThreadBurstExecutorService.terminateAllAndWait | ( | long | timeout, | |
TimeUnit | unit | |||
) | throws InterruptedException |
Attempts to stop all running threads, waiting no longer than the given timeout
. This method can be called either before executeAllAndWait 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 unit |
InterruptedException |