eu.emi.dsr.util
Class TimeoutRunner<V>

java.lang.Object
  extended by 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

Constructor Summary
TimeoutRunner(Callable<V> task, int timeout, TimeUnit unit)
           
 
Method Summary
 V call()
           
static
<Result> Result
compute(Callable<Result> task, int timeout)
          helper for computing a result using a TimeoutRunner
static
<Result> Result
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
 

Constructor Detail

TimeoutRunner

public TimeoutRunner(Callable<V> task,
                     int timeout,
                     TimeUnit unit)
Parameters:
timeout - - milliseconds before timeout
task - - the task to execute
Method Detail

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.