Package net.i2p.util
Class SimpleTimer2
java.lang.Object
net.i2p.util.SimpleTimer2
- Direct Known Subclasses:
RetransmissionTimer
Simple event scheduler - toss an event on the queue and it gets fired at the
appropriate time. The method that is fired however should NOT block (otherwise
they b0rk the timer).
This rewrites the old SimpleTimer to use the java.util.concurrent.ScheduledThreadPoolExecutor.
SimpleTimer has problems with lock contention;
this should work a lot better.
This supports cancelling and arbitrary rescheduling.
If you don't need that, use SimpleScheduler instead.
SimpleTimer is deprecated, use this or SimpleScheduler.
- Author:
- zzz
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Similar to SimpleTimer.TimedEvent but users must extend instead of implement, and all schedule and cancel methods are through this class rather than SimpleTimer2. -
Constructor Summary
ModifierConstructorDescriptionSimpleTimer2
(I2PAppContext context) To be instantiated by the context.protected
SimpleTimer2
(I2PAppContext context, String name) To be instantiated by the context.protected
SimpleTimer2
(I2PAppContext context, String name, boolean prestartAllThreads) To be instantiated by the context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEvent
(SimpleTimer.TimedEvent event, long timeoutMs) Queue up the given event to be fired no sooner than timeoutMs from now.void
addPeriodicEvent
(SimpleTimer.TimedEvent event, long timeoutMs) Schedule periodic event The TimedEvent must not do its own rescheduling.void
addPeriodicEvent
(SimpleTimer.TimedEvent event, long delay, long timeoutMs) Schedule periodic event The TimedEvent must not do its own rescheduling.static SimpleTimer2
If you have a context, use context.simpleTimer2() insteadvoid
stop()
Stops the SimpleTimer.toString()
-
Constructor Details
-
SimpleTimer2
To be instantiated by the context. Others should use context.simpleTimer2() instead -
SimpleTimer2
To be instantiated by the context. Others should use context.simpleTimer2() instead -
SimpleTimer2
To be instantiated by the context. Others should use context.simpleTimer2() instead- Since:
- 0.9
-
-
Method Details
-
getInstance
If you have a context, use context.simpleTimer2() instead -
stop
public void stop()Stops the SimpleTimer. Subsequent executions should not throw a RejectedExecutionException. Cannot be restarted. -
addEvent
Queue up the given event to be fired no sooner than timeoutMs from now. For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.- Parameters:
event
- to be run oncetimeoutMs
- run after this delay- Since:
- 0.9.20
-
addPeriodicEvent
Schedule periodic event The TimedEvent must not do its own rescheduling. As all Exceptions are caught in run(), these will not prevent subsequent executions (unlike SimpleTimer, where the TimedEvent does its own rescheduling). For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.- Parameters:
timeoutMs
- run subsequent iterations of this event every timeoutMs ms, 5000 minimum- Throws:
IllegalArgumentException
- if timeoutMs less than 5000- Since:
- 0.9.20
-
addPeriodicEvent
Schedule periodic event The TimedEvent must not do its own rescheduling. As all Exceptions are caught in run(), these will not prevent subsequent executions (unlike SimpleTimer, where the TimedEvent does its own rescheduling). For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.- Parameters:
delay
- run the first iteration of this event after delay mstimeoutMs
- run subsequent iterations of this event every timeoutMs ms, 5000 minimum- Throws:
IllegalArgumentException
- if timeoutMs less than 5000- Since:
- 0.9.20
-
toString
-