Class TimeoutCommand<T>

java.lang.Object
com.kheops.util.TimeoutCommand<T>
Type Parameters:
T - the result type of execution execute

public class TimeoutCommand<T> extends Object
A command that returns a typed result and may throw an exception. Basically wraps around a callable task to monitor execution delay. Each task are run on a cached thread pool, will typically improve the performance of running many short-lived asynchronous tasks.
  • Constructor Details

    • TimeoutCommand

      public TimeoutCommand()
  • Method Details

    • execute

      public T execute(Callable<T> task, long timeout, TimeUnit unit) throws Exception
      Executes a Callable interface with a timeout delay. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
      Parameters:
      task - instructions to be executed
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      typed result of the callable execution
      Throws:
      TimeoutException - if the operation is not executed within the configured delay.
      Exception
    • destroy

      public void destroy()
      Gracefully destroy opened resources.