Package jmri.util
Class TimerUtil
- java.lang.Object
-
- jmri.util.TimerUtil
-
@Immutable public final class TimerUtil extends java.lang.Object
Common utility methods for working with (@link java.util.Timer)Each
Timer
uses a thread, which means that they're not throw-away timers: You either track when you can destroy them (and that destruction is not obvious), or they stick around consuming resources.This class provides most of the functionality of a Timer. Some differences:
- When migrating code that uses Timer.cancel() to end operation, you have to retain references to the individual TimerTask objects and cancel them instead.
For convenience, this also provides methods to ensure that the task is invoked on a specific JMRI thread.
Please note the comment in the
Timer
Javadoc about howScheduledThreadPoolExecutor
might provide a better underlying implementation. Method JavaDoc tweaked from java.util.Timer.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.Timer
commonTimer
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
schedule(java.util.TimerTask task, long delay)
Schedules the specified task for execution after the specified delay.static void
schedule(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.static void
schedule(java.util.TimerTask task, java.util.Date time)
Schedule a TimerTask for execution at the specified time.static void
schedule(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, beginning at the specified time.static void
scheduleAtFixedRate(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.static void
scheduleAtFixedRate(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, beginning at the specified time.static void
scheduleAtFixedRateOnGUIThread(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread beginning after the specified delay.static void
scheduleAtFixedRateOnGUIThread(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, on the GUI Thread, beginning at the specified time.static void
scheduleAtFixedRateOnLayoutThread(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread beginning after the specified delay.static void
scheduleAtFixedRateOnLayoutThread(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, on the Layout Thread, beginning at the specified time.static void
scheduleOnGUIThread(java.util.TimerTask task, long delay)
Schedules the specified task for execution on the GUI Thread after the specified delay.static void
scheduleOnGUIThread(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread, beginning after the specified delay.static void
scheduleOnGUIThread(java.util.TimerTask task, java.util.Date time)
Schedule a TimerTask on GUI Thread for execution at the specified time.static void
scheduleOnGUIThread(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread, beginning at the specified time.static void
scheduleOnLayoutThread(java.util.TimerTask task, long delay)
Schedules the specified task for execution on the Layout Thread after the specified delay.static void
scheduleOnLayoutThread(java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread beginning after the specified delay.static void
scheduleOnLayoutThread(java.util.TimerTask task, java.util.Date time)
Schedule a TimerTask on Layout Thread for execution at the specified time.static void
scheduleOnLayoutThread(java.util.TimerTask task, java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread, beginning at the specified time.
-
-
-
Field Detail
-
commonTimer
static final java.util.Timer commonTimer
-
-
Method Detail
-
schedule
public static void schedule(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date time)
Schedule a TimerTask for execution at the specified time. If time is in the past, the task is scheduled for immediate execution.- Parameters:
task
- task to be scheduled.time
- time at which task is to be executed.
-
schedule
public static void schedule(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
schedule
public static void schedule(@Nonnull java.util.TimerTask task, long delay)
Schedules the specified task for execution after the specified delay.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.
-
schedule
public static void schedule(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRate
public static void scheduleAtFixedRate(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRate
public static void scheduleAtFixedRate(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleOnGUIThread
public static void scheduleOnGUIThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date time)
Schedule a TimerTask on GUI Thread for execution at the specified time. If time is in the past, the task is scheduled for immediate execution.- Parameters:
task
- task to be scheduled.time
- time at which task is to be executed.
-
scheduleOnGUIThread
public static void scheduleOnGUIThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleOnGUIThread
public static void scheduleOnGUIThread(@Nonnull java.util.TimerTask task, long delay)
Schedules the specified task for execution on the GUI Thread after the specified delay.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.
-
scheduleOnGUIThread
public static void scheduleOnGUIThread(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRateOnGUIThread
public static void scheduleAtFixedRateOnGUIThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, on the GUI Thread, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRateOnGUIThread
public static void scheduleAtFixedRateOnGUIThread(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the GUI Thread beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleOnLayoutThread
public static void scheduleOnLayoutThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date time)
Schedule a TimerTask on Layout Thread for execution at the specified time. If time is in the past, the task is scheduled for immediate execution.- Parameters:
task
- task to be scheduled.time
- time at which task is to be executed.
-
scheduleOnLayoutThread
public static void scheduleOnLayoutThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleOnLayoutThread
public static void scheduleOnLayoutThread(@Nonnull java.util.TimerTask task, long delay)
Schedules the specified task for execution on the Layout Thread after the specified delay.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.
-
scheduleOnLayoutThread
public static void scheduleOnLayoutThread(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRateOnLayoutThread
public static void scheduleAtFixedRateOnLayoutThread(@Nonnull java.util.TimerTask task, @Nonnull java.util.Date firstTime, long period)
Schedules the specified task for repeated fixed-delay execution, on the Layout Thread, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.- Parameters:
task
- task to be scheduled.firstTime
- First time at which task is to be executed.period
- time in milliseconds between successive task executions.
-
scheduleAtFixedRateOnLayoutThread
public static void scheduleAtFixedRateOnLayoutThread(@Nonnull java.util.TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution on the Layout Thread beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.- Parameters:
task
- task to be scheduled.delay
- delay in milliseconds before task is to be executed.period
- time in milliseconds between successive task executions.
-
-