SimpleTimer2: Call the 3-arg addPeridicEvenet() from the 2-arg addPeridicEvenet()

This commit is contained in:
dev
2015-04-15 14:42:39 +00:00
parent f5ba1b1b97
commit 3a57310fbe

View File

@ -131,13 +131,15 @@ public class SimpleTimer2 {
* @param event * @param event
* @param timeoutMs * @param timeoutMs
*/ */
public void addEvent(final SimpleTimer.TimedEvent event, long timeoutMs) { public void addEvent(final SimpleTimer.TimedEvent event, final long timeoutMs) {
if (event == null) if (event == null)
throw new IllegalArgumentException("addEvent null"); throw new IllegalArgumentException("addEvent null");
new TimedEvent(this, timeoutMs) { new TimedEvent(this, timeoutMs) {
long absTime = System.currentTimeMillis() + timeoutMs;
@Override @Override
public void timeReached() { public void timeReached() {
System.out.println("Event scheduled for: " + absTime + " started at: " + System.currentTimeMillis() + ", diff: " + (System.currentTimeMillis() - absTime));
event.timeReached(); event.timeReached();
} }
}; };
@ -152,17 +154,10 @@ public class SimpleTimer2 {
* its own rescheduling). * its own rescheduling).
* *
* @since 0.9.20 * @since 0.9.20
* @param delay run the first iteration of this event after delay ms
* @param timeoutMs run subsequent iterations of this event every timeoutMs ms * @param timeoutMs run subsequent iterations of this event every timeoutMs ms
*/ */
public void addPeriodicEvent(final SimpleTimer.TimedEvent event, final long timeoutMs) { public void addPeriodicEvent(final SimpleTimer.TimedEvent event, final long timeoutMs) {
addPeriodicEvent(event, timeoutMs, timeoutMs);
new PeriodicTimedEvent(this, timeoutMs, timeoutMs) {
@Override
public void timeReached() {
event.timeReached();
}
};
} }
/** /**