eu.emi.dsr.util
Class TimeoutRunner<V>
java.lang.Object
eu.emi.dsr.util.TimeoutRunner<V>
- Type Parameters:
V - - the type of result
- All Implemented Interfaces:
- Callable<V>
public class TimeoutRunner<V>
- extends Object
- implements Callable<V>
runs a task with an external timeout
- Author:
- schuller
|
Method Summary |
V |
call()
|
static
|
compute(Callable<Result> task,
int timeout)
helper for computing a result using a TimeoutRunner |
static
|
compute(Callable<Result> task,
int timeout,
TimeUnit units)
helper for computing a result using a TimeoutRunner |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TimeoutRunner
public TimeoutRunner(Callable<V> task,
int timeout,
TimeUnit unit)
- Parameters:
timeout - - milliseconds before timeouttask - - the task to execute
call
public V call()
throws RejectedExecutionException,
InterruptedException
- Specified by:
call in interface Callable<V>
- Throws:
RejectedExecutionException
InterruptedException
compute
public static <Result> Result compute(Callable<Result> task,
int timeout)
- helper for computing a result using a TimeoutRunner
- Type Parameters:
Result - - Parameters:
task - timeout - - time out in milliseconds
- Returns:
- a Result or
null if the timeout is reached, or an exception occurs
compute
public static <Result> Result compute(Callable<Result> task,
int timeout,
TimeUnit units)
- helper for computing a result using a TimeoutRunner
- Type Parameters:
Result - - Parameters:
task - timeout - units - the TimeUnit to use
- Returns:
- a Result or
null if the timeout is reached
Copyright © 2012. All Rights Reserved.