Package gov.usgs.util
Class FutureExecutorTask<T>
- java.lang.Object
-
- gov.usgs.util.ExecutorTask<T>
-
- gov.usgs.util.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 Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ExecutorService
backgroundService
ExecutorService used to execute callable.static int
DEFAULT_NUM_TRIES
Default number of tries to run this task.static long
DEFAULT_RETRY_DELAY
Default number of milliseconds to wait before a retry.static long
DEFAULT_TIMEOUT
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
Constructors Constructor Description 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.FutureExecutorTask(java.util.concurrent.ExecutorService backgroundService, java.util.concurrent.ExecutorService service, int maxTries, long timeout, java.util.concurrent.Callable<T> callable)
Construct a new ExecutorTaskFutureExecutorTask(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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 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 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:
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 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:
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 interfacejava.lang.Runnable
- Overrides:
run
in classExecutorTask<T>
-
-