use of com.serotonin.timer.TimeSource in project ma-core-public by infiniteautomation.
the class FixedRateTest method main.
public static void main(String[] args) {
RealTimeTimer timer = new RealTimeTimer();
timer.setTimeSource(new TimeSource() {
int count = 10;
@Override
public long currentTimeMillis() {
long time;
if (count-- > 0)
time = System.currentTimeMillis();
else
time = System.currentTimeMillis() - 1000001000;
System.out.println("Returning " + new Date(time));
return time;
}
});
timer.init();
long period = 5000;
long delay = period - (System.currentTimeMillis() % period);
FixedRateTrigger trigger = new FixedRateTrigger(delay, period);
TimerTask task = new TimerTask(trigger, "Test Timer Task") {
@Override
public void run(long runtime) {
System.out.println("executed at " + new Date(runtime));
}
@Override
public void rejected(RejectedTaskReason reason) {
System.out.println("task rejected: " + reason.getDescription());
}
};
timer.schedule(task);
try {
synchronized (timer) {
timer.wait(30000);
}
} catch (InterruptedException e) {
// no op
}
timer.cancel();
}
Aggregations