[concurrency-interest] ScheduledThreadPoolExecutor schdeuling problem ?
hanson.char at gmail.com
Wed Jan 2 03:00:05 EST 2008
On Dec 31, 2007 1:17 PM, Hanson Char <hanson.char at gmail.com> wrote:
> Should the task got executed by the scheduler happened earlier than
> the target/absolute time, the proper solution would probably be to
> skip the execution but immediately reschedule the task to execute at
> the same target/absolute time again (by calculating the difference
> between the then current time and the target time, both only available
> in millisec).
On 2nd thought, the task executed by the scheduler actually took place
at the correct target time. It's the System.currentTimeMillis() at
that moment that could return a value which is not up-to-date enough
and therefore makes it appears as if the task got executed earlier
than it should.
Should such scheduled task appears to take place earlier than the
current/original target time, it should still execute (since that is
actually the right moment despite the outdated value from
System.currentTimeMillis()), and then be scheduled, if necessary, for
the next execution with a delay equal to the difference between the
next target time and the current/original target time.
More information about the Concurrency-interest