Package gov.usgs.util
Class FutureExecutorTask<T>
java.lang.Object
gov.usgs.util.ExecutorTask<T>
gov.usgs.util.FutureExecutorTask<T>
FutureExecutorTask overrides how timeouts are handled to use a separate
executor service with Futures.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorService
ExecutorService used to execute callable.static final int
Default number of tries to run this task.static final long
Default number of milliseconds to wait before a retry.static final long
Default timeout for this task.Fields inherited from class gov.usgs.util.ExecutorTask
callable, cancelled, done, maxTries, name, numTries, result, retryDelay, retryTimer, runThread, service, syncObject, timeout
-
Constructor Summary
ConstructorsConstructorDescriptionFutureExecutorTask
(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Runnable runnable, T result) Wraps a runnable and result using the CallableRunnable class.FutureExecutorTask
(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Callable<T> callable) Construct a new ExecutorTaskFutureExecutorTask
(ExecutorService backgroundService, ExecutorService service, int maxTries, long timeout, Callable<T> callable, Timer retryTimer, long retryDelay) Construct a new FutureExecutorTask -
Method Summary
Modifier and TypeMethodDescriptionvoid
run()
Run calls the callable, scheduling timeout interruption, catching exceptions, and potentially resubmitting to the executor service.Methods inherited from class gov.usgs.util.ExecutorTask
cancel, get, get, getCallable, getExceptions, getMaxTries, getName, getNumTries, getRetryDelay, getRetryTimer, isCancelled, isDone, setDone, setName, setRetryDelay, setRetryTimer
-
Field Details
-
DEFAULT_RETRY_DELAY
public static final long DEFAULT_RETRY_DELAYDefault number of milliseconds to wait before a retry.- See Also:
-
DEFAULT_NUM_TRIES
public static final int DEFAULT_NUM_TRIESDefault number of tries to run this task.- See Also:
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault timeout for this task.- See Also:
-
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 callableservice
- 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 runnableresult
- 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 callableservice
- 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 interfaceRunnable
- Overrides:
run
in classExecutorTask<T>
-