public class ExecutorWithTimeout
extends java.lang.Object
Callables so that the total accumulated time will stay
within the total timeoutms that is given in the constructor.
This executor will run a separate timer and kill the Callable with
thread.stop() to make a pretty hard kill attempt if the time runs out.| Constructor and Description |
|---|
ExecutorWithTimeout(long timeoutms)
Construct an executor with a total available amount of time.
|
| Modifier and Type | Method and Description |
|---|---|
<V> V |
execute(java.lang.String name,
java.util.concurrent.Callable<V> command)
Execute the command within the remaining time of this executor.
|
public ExecutorWithTimeout(long timeoutms)
timeoutms - the total available time that this executor can spend.public <V> V execute(java.lang.String name,
java.util.concurrent.Callable<V> command)
throws java.util.concurrent.ExecutionException,
java.util.concurrent.TimeoutException
name - the name of the thread/process/agent for which we are
executing. Used for error reporting.command - the Callable to executejava.util.concurrent.ExecutionException - if the Callable threw an exception. The
ExecutionException will contain the exception from
the Callable.java.util.concurrent.TimeoutException - if the Callable did not finish in time.