Package gov.usgs.util

Class FutureExecutorTask<T>

  • All Implemented Interfaces:
    java.lang.Runnable, java.util.concurrent.Future<T>

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

      • DEFAULT_RETRY_DELAY

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

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

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

        protected java.util.concurrent.ExecutorService backgroundService
        ExecutorService used to execute callable.
    • Constructor Detail

      • FutureExecutorTask

        public FutureExecutorTask​(java.util.concurrent.ExecutorService backgroundService,
                                  java.util.concurrent.ExecutorService service,
                                  int maxTries,
                                  long timeout,
                                  java.util.concurrent.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:
        InterruptedException
      • FutureExecutorTask

        public FutureExecutorTask​(java.util.concurrent.ExecutorService backgroundService,
                                  java.util.concurrent.ExecutorService service,
                                  int maxTries,
                                  long timeout,
                                  java.lang.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:
        Executors.callable(Runnable, Object)
      • FutureExecutorTask

        public FutureExecutorTask​(java.util.concurrent.ExecutorService backgroundService,
                                  java.util.concurrent.ExecutorService service,
                                  int maxTries,
                                  long timeout,
                                  java.util.concurrent.Callable<T> callable,
                                  java.util.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:
        on interrupted
    • Method Detail

      • 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 java.lang.Runnable
        Overrides:
        run in class ExecutorTask<T>