imace / jetlang

Automatically exported from code.google.com/p/jetlang
0 stars 0 forks source link

schedule by absolute time, not just relative #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Would you add a call to your scheduler to schedule by absolute time, as 
well as by relative time?  Its simple to make the absolute scheduling call 
a wrapper for the relative one by making the absolute time relative to the 
current time.  It's a policy decision if absolute times in the past are 
rejected or mean "run now".  Thus:

public Disposable scheduleAt(Runnable _command, long absolute, TimeUnit 
unit) {
    long delay = TimeUnit.MILLISECONDS.convert(absolute, unit) - 
System.currentTimeMillis();
    return schedule(delay, TimeUnit.MILLISECONDS);
}

I let "schedule" decide what the policy is for negative delays.

Ugly point - I lose precision better the millis.  There's no good wall 
clock call in Java, so I try to lose gracefully.

On Windows you need a trick to get millisecond precision: 
http://binkley.blogspot.com/2010/03/no-time-for-windows.html

Original issue reported on code.google.com by b.k.ox...@gmail.com on 27 Apr 2010 at 11:50

GoogleCodeExporter commented 9 years ago

Original comment by mike.ret...@gmail.com on 25 Aug 2010 at 9:39