ConstantTimeWatchdog
@Deprecated public class Watchdog extends ConstantTimeWatchdog
ListenableFuture
is completed within a
timeout. Once the timeout is reached, if the future has not already completed this will
attempt to invoke Future.cancel(boolean)
. The future should then throw a
CancellationException
on a Future.get()
call.
Using CancelDebuggingListenableFuture
to wrap the futures before providing to this class
can provide an easier understanding of the state of a Future when it was timed out by this class.
Constructor and Description |
---|
Watchdog(long timeoutInMillis,
boolean sendInterruptOnFutureCancel)
Deprecated.
Constructs a new
Watchdog . |
Watchdog(SubmitterScheduler scheduler,
long timeoutInMillis,
boolean sendInterruptOnFutureCancel)
Deprecated.
Constructs a new
Watchdog with a scheduler of your choosing. |
Modifier and Type | Method and Description |
---|---|
int |
getWatchingCount()
Check how many futures are currently being monitored for completion.
|
boolean |
isActive()
Checks to see if this watchdog is currently active.
|
getTimeoutInMillis, watch
public Watchdog(long timeoutInMillis, boolean sendInterruptOnFutureCancel)
Watchdog
. This constructor will use a default static scheduler
(which is lazily constructed). This should be fine in most cases, but you can provide your
own scheduler if you have specific needs where the CentralThreadlyPool
default is not
a good option.timeoutInMillis
- Time in milliseconds that futures will be set to error if they are not donesendInterruptOnFutureCancel
- If true
, and a thread is provided with the future,
an interrupt will be sent on timeoutpublic Watchdog(SubmitterScheduler scheduler, long timeoutInMillis, boolean sendInterruptOnFutureCancel)
Watchdog
with a scheduler of your choosing. It is critical that
this scheduler has a free thread available to inspect futures which may not have completed in
the given timeout. You may want to use a org.threadly.concurrent.limiter to ensure that
there are threads available.scheduler
- Scheduler to schedule task to look for expired futurestimeoutInMillis
- Time in milliseconds that futures will be set to error if they are not donesendInterruptOnFutureCancel
- If true
, and a thread is provided with the future,
an interrupt will be sent on timeoutpublic boolean isActive()
true
if this watchdog is currently in usepublic int getWatchingCount()