Package jmri.util
Class TimerUtil
java.lang.Object
jmri.util.TimerUtil
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 how
ScheduledThreadPoolExecutor might provide a better
underlying implementation.
Method JavaDoc tweaked from java.util.Timer.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidSchedules the specified task for execution after the specified delay.static voidSchedules the specified task for repeated fixed-delay execution, beginning after the specified delay.static voidSchedule a TimerTask for execution at the specified time.static voidSchedules the specified task for repeated fixed-delay execution, beginning at the specified time.static voidscheduleAtFixedRate(TimerTask task, long delay, long period) Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.static voidscheduleAtFixedRate(TimerTask task, Date firstTime, long period) Schedules the specified task for repeated fixed-delay execution, beginning at the specified time.static voidscheduleAtFixedRateOnGUIThread(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 voidscheduleAtFixedRateOnGUIThread(TimerTask task, Date firstTime, long period) Schedules the specified task for repeated fixed-delay execution, on the GUI Thread, beginning at the specified time.static voidscheduleAtFixedRateOnLayoutThread(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 voidscheduleAtFixedRateOnLayoutThread(TimerTask task, Date firstTime, long period) Schedules the specified task for repeated fixed-delay execution, on the Layout Thread, beginning at the specified time.static voidscheduleOnGUIThread(TimerTask task, long delay) Schedules the specified task for execution on the GUI Thread after the specified delay.static voidscheduleOnGUIThread(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 voidscheduleOnGUIThread(TimerTask task, Date time) Schedule a TimerTask on GUI Thread for execution at the specified time.static voidscheduleOnGUIThread(TimerTask task, Date firstTime, long period) Schedules the specified task for repeated fixed-delay execution on the GUI Thread, beginning at the specified time.static voidscheduleOnLayoutThread(TimerTask task, long delay) Schedules the specified task for execution on the Layout Thread after the specified delay.static voidscheduleOnLayoutThread(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 voidscheduleOnLayoutThread(TimerTask task, Date time) Schedule a TimerTask on Layout Thread for execution at the specified time.static voidscheduleOnLayoutThread(TimerTask task, Date firstTime, long period) Schedules the specified task for repeated fixed-delay execution on the Layout Thread, beginning at the specified time.
-
Field Details
-
commonTimer
-
-
Method Details
-
schedule
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
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
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
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 TimerTask task, @Nonnull 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
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
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 TimerTask task, @Nonnull 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
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
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 TimerTask task, @Nonnull 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
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
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 TimerTask task, @Nonnull 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
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
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 TimerTask task, @Nonnull 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 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.
-