/** * Constructs a new {@link 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 {@link CentralThreadlyPool} default is not * a good option. * * @param timeoutInMillis Time in milliseconds that futures will be set to error if they are not done * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout */ public Watchdog(long timeoutInMillis, boolean sendInterruptOnFutureCancel) { this(getStaticScheduler(), timeoutInMillis, sendInterruptOnFutureCancel); }
/** * Constructs a new {@link 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 {@link CentralThreadlyPool} default is not * a good option. * * @param timeoutInMillis Time in milliseconds that futures will be set to error if they are not done * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout */ public Watchdog(long timeoutInMillis, boolean sendInterruptOnFutureCancel) { this(getStaticScheduler(), timeoutInMillis, sendInterruptOnFutureCancel); }
/** * Constructs a new {@link WatchdogCache}. 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 want to avoid the thread creation (which is shared among all instances * that were constructed with this constructor or {@link Watchdog#Watchdog(long, boolean)}}. * * @deprecated Please use {@link #centralWatchdogCache(boolean)} * * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout */ @Deprecated public WatchdogCache(boolean sendInterruptOnFutureCancel) { this(Watchdog.getStaticScheduler(), sendInterruptOnFutureCancel, DEFAULT_RESOLUTION_MILLIS); }
/** * Constructs a new {@link WatchdogCache}. 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 want to avoid the thread creation (which is shared among all instances * that were constructed with this constructor or {@link Watchdog#Watchdog(long, boolean)}}. * * @deprecated Please use {@link #centralWatchdogCache(boolean)} * * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout */ @Deprecated public WatchdogCache(boolean sendInterruptOnFutureCancel) { this(Watchdog.getStaticScheduler(), sendInterruptOnFutureCancel, DEFAULT_RESOLUTION_MILLIS); }
/** * Return a static / shared {@link WatchdogCache} instance. This instance is backed by the * {@link org.threadly.concurrent.CentralThreadlyPool} which should be fine in most cases, but if * you have specific needs you can construct your own instance by * {@link #WatchdogCache(SubmitterScheduler, boolean)}, or if you need to specify a specific * timeout resolution using the {@link #WatchdogCache(SubmitterScheduler, boolean, long)} * constructor. * <p> * As long as those special cases are not needed, using a shared instance allows for potentially * improved efficiency. * * @since 5.19 * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout * @return A shared {@link WatchdogCache} with the specified configuration */ public static final WatchdogCache centralWatchdogCache(boolean sendInterruptOnFutureCancel) { AtomicReference<WatchdogCache> ar = sendInterruptOnFutureCancel ? INTERRUPTING_WATCHDOG_CACHE : NONINTERRUPTING_WATCHDOG_CACHE; WatchdogCache wd = ar.get(); if (wd == null) { ar.compareAndSet(null, new WatchdogCache(Watchdog.getStaticScheduler(), sendInterruptOnFutureCancel)); wd = ar.get(); } return wd; }
/** * Return a static / shared {@link WatchdogCache} instance. This instance is backed by the * {@link org.threadly.concurrent.CentralThreadlyPool} which should be fine in most cases, but if * you have specific needs you can construct your own instance by * {@link #WatchdogCache(SubmitterScheduler, boolean)}, or if you need to specify a specific * timeout resolution using the {@link #WatchdogCache(SubmitterScheduler, boolean, long)} * constructor. * <p> * As long as those special cases are not needed, using a shared instance allows for potentially * improved efficiency. * * @since 5.19 * @param sendInterruptOnFutureCancel If {@code true}, and a thread is provided with the future, * an interrupt will be sent on timeout * @return A shared {@link WatchdogCache} with the specified configuration */ public static final WatchdogCache centralWatchdogCache(boolean sendInterruptOnFutureCancel) { AtomicReference<WatchdogCache> ar = sendInterruptOnFutureCancel ? INTERRUPTING_WATCHDOG_CACHE : NONINTERRUPTING_WATCHDOG_CACHE; WatchdogCache wd = ar.get(); if (wd == null) { ar.compareAndSet(null, new WatchdogCache(Watchdog.getStaticScheduler(), sendInterruptOnFutureCancel)); wd = ar.get(); } return wd; }