Patch applied. Thanks. It restores the old "scheduleAtFixedRate" on the ScheduledExecutorService which is correct.
I had to change the last line of the test from
Assert.assertEquals(10, count.intValue());
to
Assert.assertTrue(count.intValue() >= 10);
to have it reliably green.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thinking at it again, I believe that it is still not fully correct:
job.setTargetExecutionTime(System.currentTimeMillis() + job.getPeriod());
should probably be changed to:
job.setTargetExecutionTime(job.getTargetExecutionTime() + job.getPeriod());
in order to really have the old behaviour of scheduleAtFixedRate.
If you have time to verify it, it would be welcome.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
job.setTargetExecutionTime should be set to the minimum n (n = 1, 2, 3, ...) such that job.getTargetExecutionTime() + n * job.getPeriod () > System.currentTimeMillis()
(effectively all the lower values of n are dropped, as per the blog).
The following code should work.
long currentTime = System.currentTimeMillis();
long timeDifference = currentTime - job.getTargetExecutionTime();
if (timeDifference % job.getPeriod() > 0) {
timeDifference = (timeDifference / job.getPeriod()) * job.getPeriod() + job.getPeriod();
}
job.setTargetExecutionTime(job.getTargetExecutionTime() + timeDifference);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Patch applied. Thanks. It restores the old "scheduleAtFixedRate" on the ScheduledExecutorService which is correct.
I had to change the last line of the test from
Assert.assertEquals(10, count.intValue());
to
Assert.assertTrue(count.intValue() >= 10);
to have it reliably green.
Thinking at it again, I believe that it is still not fully correct:
job.setTargetExecutionTime(System.currentTimeMillis() + job.getPeriod());
should probably be changed to:
job.setTargetExecutionTime(job.getTargetExecutionTime() + job.getPeriod());
in order to really have the old behaviour of scheduleAtFixedRate.
If you have time to verify it, it would be welcome.
Hey Marc,
You are right about the setTargetExecutionTime. As per John Resig's blog, http://ejohn.org/blog/how-javascript-timers-work/
job.setTargetExecutionTime should be set to the minimum n (n = 1, 2, 3, ...) such that job.getTargetExecutionTime() + n * job.getPeriod () > System.currentTimeMillis()
(effectively all the lower values of n are dropped, as per the blog).
The following code should work.
long currentTime = System.currentTimeMillis();
long timeDifference = currentTime - job.getTargetExecutionTime();
if (timeDifference % job.getPeriod() > 0) {
timeDifference = (timeDifference / job.getPeriod()) * job.getPeriod() + job.getPeriod();
}
job.setTargetExecutionTime(job.getTargetExecutionTime() + timeDifference);