Skip to content

Commit

Permalink
Allow override of scheduler (#3132)
Browse files Browse the repository at this point in the history
Refs #2931
  • Loading branch information
dkaukov committed Feb 9, 2023
1 parent 22ff3dd commit 47f9eaf
Showing 1 changed file with 13 additions and 1 deletion.
Expand Up @@ -8,6 +8,7 @@
import java.util.Locale;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -170,14 +171,25 @@ synchronized void start(long initialDelay, long period, TimeUnit unit, Runnable
}


/**
* Schedule the task, and return a future.
*
* @deprecated Use {@link #getScheduledFuture(long, long, TimeUnit, Runnable, ScheduledExecutorService)} instead.
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
protected ScheduledFuture<?> getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable) {
return getScheduledFuture(initialDelay, period, unit, runnable, this.executor);
}

/**
* Schedule the task, and return a future.
* The current implementation uses scheduleWithFixedDelay, replacing scheduleWithFixedRate. This avoids queueing issues, but may
* cause some reporters to skip metrics, as scheduleWithFixedDelay introduces a growing delta from the original start point.
*
* Overriding this in a subclass to revert to the old behavior is permitted.
*/
protected ScheduledFuture<?> getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable) {
protected ScheduledFuture<?> getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable, ScheduledExecutorService executor) {
return executor.scheduleWithFixedDelay(runnable, initialDelay, period, unit);
}

Expand Down

0 comments on commit 47f9eaf

Please sign in to comment.