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@1174951 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-09-23 18:48:19 +00:00
parent 2db7cbf436
commit 1453c53105
1 changed files with 14 additions and 14 deletions

View File

@ -23,25 +23,25 @@ import org.apache.activemq.util.ServiceStopper;
import org.apache.activemq.util.ServiceSupport; import org.apache.activemq.util.ServiceSupport;
/** /**
* *
*/ */
public final class Scheduler extends ServiceSupport { public final class Scheduler extends ServiceSupport {
private final String name; private final String name;
private Timer timer; private Timer timer;
private final HashMap<Runnable, TimerTask> timerTasks = new HashMap<Runnable, TimerTask>(); private final HashMap<Runnable, TimerTask> timerTasks = new HashMap<Runnable, TimerTask>();
public Scheduler (String name) { public Scheduler (String name) {
this.name = name; this.name = name;
} }
public void executePeriodically(final Runnable task, long period) { public void executePeriodically(final Runnable task, long period) {
TimerTask timerTask = new SchedulerTimerTask(task); TimerTask timerTask = new SchedulerTimerTask(task);
timer.scheduleAtFixedRate(timerTask, period, period); timer.schedule(timerTask, period, period);
timerTasks.put(task, timerTask); timerTasks.put(task, timerTask);
} }
/* /*
* execute on rough schedual based on termination of last execution. There is no * execute on rough schedule based on termination of last execution. There is no
* compensation (two runs in quick succession) for delays * compensation (two runs in quick succession) for delays
*/ */
public synchronized void schedualPeriodically(final Runnable task, long period) { public synchronized void schedualPeriodically(final Runnable task, long period) {
@ -49,9 +49,9 @@ public final class Scheduler extends ServiceSupport {
timer.schedule(timerTask, period, period); timer.schedule(timerTask, period, period);
timerTasks.put(task, timerTask); timerTasks.put(task, timerTask);
} }
public synchronized void cancel(Runnable task) { public synchronized void cancel(Runnable task) {
TimerTask ticket = timerTasks.remove(task); TimerTask ticket = timerTasks.remove(task);
if (ticket != null) { if (ticket != null) {
ticket.cancel(); ticket.cancel();
timer.purge();//remove cancelled TimerTasks timer.purge();//remove cancelled TimerTasks
@ -59,10 +59,10 @@ public final class Scheduler extends ServiceSupport {
} }
public synchronized void executeAfterDelay(final Runnable task, long redeliveryDelay) { public synchronized void executeAfterDelay(final Runnable task, long redeliveryDelay) {
TimerTask timerTask = new SchedulerTimerTask(task); TimerTask timerTask = new SchedulerTimerTask(task);
timer.schedule(timerTask, redeliveryDelay); timer.schedule(timerTask, redeliveryDelay);
} }
public void shutdown() { public void shutdown() {
timer.cancel(); timer.cancel();
} }
@ -70,7 +70,7 @@ public final class Scheduler extends ServiceSupport {
@Override @Override
protected synchronized void doStart() throws Exception { protected synchronized void doStart() throws Exception {
this.timer = new Timer(name, true); this.timer = new Timer(name, true);
} }
@Override @Override
@ -78,7 +78,7 @@ public final class Scheduler extends ServiceSupport {
if (this.timer != null) { if (this.timer != null) {
this.timer.cancel(); this.timer.cancel();
} }
} }
public String getName() { public String getName() {