|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.i2p.util.SimpleTimer2
public class SimpleTimer2
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.
Nested Class Summary | |
---|---|
static class |
SimpleTimer2.TimedEvent
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 | |
---|---|
|
SimpleTimer2(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 | |
---|---|
void |
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 |
getInstance()
If you have a context, use context.simpleTimer2() instead |
void |
stop()
Stops the SimpleTimer. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SimpleTimer2(I2PAppContext context)
protected SimpleTimer2(I2PAppContext context, String name)
protected SimpleTimer2(I2PAppContext context, String name, boolean prestartAllThreads)
Method Detail |
---|
public static SimpleTimer2 getInstance()
public void stop()
public void addEvent(SimpleTimer.TimedEvent event, long timeoutMs)
event
- to be run oncetimeoutMs
- run after this delaypublic void addPeriodicEvent(SimpleTimer.TimedEvent event, long timeoutMs)
timeoutMs
- run subsequent iterations of this event every timeoutMs ms, 5000 minimum
IllegalArgumentException
- if timeoutMs less than 5000public void addPeriodicEvent(SimpleTimer.TimedEvent event, long delay, long timeoutMs)
delay
- run the first iteration of this event after delay mstimeoutMs
- run subsequent iterations of this event every timeoutMs ms, 5000 minimum
IllegalArgumentException
- if timeoutMs less than 5000public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |