Package gov.usgs.util

Class FutureExecutorTask<T>

java.lang.Object
gov.usgs.util.ExecutorTask<T>
gov.usgs.util.FutureExecutorTask<T>
All Implemented Interfaces:
Runnable, Future<T>

public class FutureExecutorTask<T> extends ExecutorTask<T>
FutureExecutorTask overrides how timeouts are handled to use a separate executor service with Futures.
  • Field Details

    • DEFAULT_RETRY_DELAY

      public static final long DEFAULT_RETRY_DELAY
      Default number of milliseconds to wait before a retry.
      See Also:
    • DEFAULT_NUM_TRIES

      public static final int DEFAULT_NUM_TRIES
      Default number of tries to run this task.
      See Also:
    • DEFAULT_TIMEOUT

      public static final long DEFAULT_TIMEOUT
      Default timeout for this task.
      See Also:
    • backgroundService

      protected ExecutorService backgroundService
      ExecutorService used to execute callable.
  • Constructor Details

    • FutureExecutorTask

      public FutureExecutorTask(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Callable<T> callable)
      Construct a new ExecutorTask
      Parameters:
      backgroundService - ExecutorService used to execute callable.
      service - ExecutorService that this task will be submitted to.
      maxTries - maximum number of tries callable can throw an exception or timeout before giving up. < 1 means never run.
      timeout - number of milliseconds to allow callable to run before it is interrupted. <= 0 means never timeout.
      callable - the callable to call. To work well, the callable should handle interrupts gracefully.
      See Also:
    • FutureExecutorTask

      public FutureExecutorTask(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Runnable runnable, T result)
      Wraps a runnable and result using the CallableRunnable class.
      Parameters:
      backgroundService - ExecutorService used to execute callable
      service - ExecutorService that this task will be submitted to.
      maxTries - maximum number of tries callable can throw an exception or timeout before giving up. < 1 means never run.
      timeout - number of milliseconds to allow callable to run before it is interrupted. <= 0 means never timeout.
      runnable - a runnable
      result - the result passed to Executors callable
      See Also:
    • FutureExecutorTask

      public FutureExecutorTask(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Callable<T> callable, Timer retryTimer, long retryDelay)
      Construct a new FutureExecutorTask
      Parameters:
      backgroundService - ExecutorService used to execute callable
      service - ExecutorService that this task will be submitted to.
      maxTries - maximum number of tries callable can throw an exception or timeout before giving up. < 1 means never run.
      timeout - number of milliseconds to allow callable to run before it is interrupted. <= 0 means never timeout.
      callable - the callable to call. To work well, the callable should handle interrupts gracefully.
      retryTimer - a timer used to schedule retries when retryDelay is non-zero.
      retryDelay - the number of milliseconds to wait before retrying after an exception.
      See Also:
  • Method Details

    • run

      public void run()
      Run calls the callable, scheduling timeout interruption, catching exceptions, and potentially resubmitting to the executor service.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class ExecutorTask<T>