From 31b77d9ade4c3f92d8218063525a3ba85604b563 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 25 Oct 2012 16:34:38 +0200 Subject: [PATCH] Cleaned up implementation. --- .../jetty/util/thread/TimerScheduler.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java index f0dd1abe382..6b4f98f15a5 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java @@ -20,19 +20,22 @@ package org.eclipse.jetty.util.thread; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.component.AbstractLifeCycle; public class TimerScheduler extends AbstractLifeCycle implements Scheduler { - /* this class uses the Timer class rather than an ScheduledExecutionService because + /* + * This class uses the Timer class rather than an ScheduledExecutionService because * it uses the same algorithm internally and the signature is cheaper to use as there are no * Futures involved (which we do not need). * However, Timer is still locking and a concurrent queue would be better. */ - Timer _timer; - final String _name; + + private final String _name; + private Timer _timer; public TimerScheduler() { @@ -63,20 +66,18 @@ public class TimerScheduler extends AbstractLifeCycle implements Scheduler public Task schedule(final Runnable task, final long delay, final TimeUnit units) { Timer timer=_timer; - if (timer!=null) - { - SimpleTask t = new SimpleTask(task); - _timer.schedule(t,units.toMillis(delay)); - return t; - } - throw new IllegalStateException("STOPPED: "+this); + if (timer==null) + throw new RejectedExecutionException("STOPPED: "+this); + SimpleTask t = new SimpleTask(task); + timer.schedule(t,units.toMillis(delay)); + return t; } private static class SimpleTask extends TimerTask implements Task { private final Runnable _task; - SimpleTask(Runnable runnable) + private SimpleTask(Runnable runnable) { _task=runnable; } @@ -87,6 +88,4 @@ public class TimerScheduler extends AbstractLifeCycle implements Scheduler _task.run(); } } - - }