mirror of https://github.com/apache/activemq.git
Don't use the scheduleAtFixedRate method in our scheduler as we don't really have a need for real time task execution, just use the fixed delay scheduler so that jobs don't stack up. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1174952 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1453c53105
commit
ca90cc7b8c
|
@ -21,26 +21,26 @@ import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class Scheduler {
|
public final class Scheduler {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final Timer CLOCK_DAEMON = new Timer("KahaDB Scheduler", true);
|
|
||||||
|
public static final Timer CLOCK_DAEMON = new Timer("KahaDB Scheduler", true);
|
||||||
private static final HashMap<Runnable, TimerTask> TIMER_TASKS = new HashMap<Runnable, TimerTask>();
|
private static final HashMap<Runnable, TimerTask> TIMER_TASKS = new HashMap<Runnable, TimerTask>();
|
||||||
|
|
||||||
private Scheduler() {
|
private Scheduler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void executePeriodically(final Runnable task, long period) {
|
public static synchronized void executePeriodically(final Runnable task, long period) {
|
||||||
TimerTask timerTask = new SchedulerTimerTask(task);
|
TimerTask timerTask = new SchedulerTimerTask(task);
|
||||||
CLOCK_DAEMON.scheduleAtFixedRate(timerTask, period, period);
|
CLOCK_DAEMON.schedule(timerTask, period, period);
|
||||||
TIMER_TASKS.put(task, timerTask);
|
TIMER_TASKS.put(task, timerTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void cancel(Runnable task) {
|
public static synchronized void cancel(Runnable task) {
|
||||||
TimerTask ticket = TIMER_TASKS.remove(task);
|
TimerTask ticket = TIMER_TASKS.remove(task);
|
||||||
if (ticket != null) {
|
if (ticket != null) {
|
||||||
ticket.cancel();
|
ticket.cancel();
|
||||||
CLOCK_DAEMON.purge();//remove cancelled TimerTasks
|
CLOCK_DAEMON.purge();//remove cancelled TimerTasks
|
||||||
|
@ -48,10 +48,10 @@ public final class Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeAfterDelay(final Runnable task, long redeliveryDelay) {
|
public static void executeAfterDelay(final Runnable task, long redeliveryDelay) {
|
||||||
TimerTask timerTask = new SchedulerTimerTask(task);
|
TimerTask timerTask = new SchedulerTimerTask(task);
|
||||||
CLOCK_DAEMON.schedule(timerTask, redeliveryDelay);
|
CLOCK_DAEMON.schedule(timerTask, redeliveryDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
CLOCK_DAEMON.cancel();
|
CLOCK_DAEMON.cancel();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue