Synchronize method and remove old deprecated schedule method.
This commit is contained in:
Timothy Bish 2014-06-28 10:21:34 -04:00
parent 1c97a65b45
commit 106f759571
2 changed files with 7 additions and 19 deletions

View File

@ -560,7 +560,7 @@ public class Topic extends BaseDestination implements Task {
} }
if (getExpireMessagesPeriod() > 0) { if (getExpireMessagesPeriod() > 0) {
scheduler.schedualPeriodically(expireMessagesTask, getExpireMessagesPeriod()); scheduler.executePeriodically(expireMessagesTask, getExpireMessagesPeriod());
} }
} }

View File

@ -27,28 +27,16 @@ 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 synchronized void executePeriodically(final Runnable task, long period) {
TimerTask timerTask = new SchedulerTimerTask(task);
timer.schedule(timerTask, period, period);
timerTasks.put(task, timerTask);
}
/*
* execute on rough schedule based on termination of last execution. There is no
* compensation (two runs in quick succession) for delays
*
* @deprecated use {@link #executePeriodically}
*/
@Deprecated
public synchronized void schedualPeriodically(final Runnable task, long period) {
TimerTask timerTask = new SchedulerTimerTask(task); TimerTask timerTask = new SchedulerTimerTask(task);
timer.schedule(timerTask, period, period); timer.schedule(timerTask, period, period);
timerTasks.put(task, timerTask); timerTasks.put(task, timerTask);
@ -78,9 +66,9 @@ public final class Scheduler extends ServiceSupport {
@Override @Override
protected synchronized void doStop(ServiceStopper stopper) throws Exception { protected synchronized void doStop(ServiceStopper stopper) throws Exception {
if (this.timer != null) { if (this.timer != null) {
this.timer.cancel(); this.timer.cancel();
} }
} }
public String getName() { public String getName() {