Menu

#1044 [Patch attached] Fixes getJobCount() for periodic JS jobs

closed
None
5
2012-10-21
2010-03-10
Amit Manjhi
No

Plus, adds a simple test case. Apply the patch using "patch -p2 < periodicJobFix.patch"

Discussion

  • Amit Manjhi

    Amit Manjhi - 2010-03-10
     
  • Marc Guillemot

    Marc Guillemot - 2010-03-11

    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.

     
  • Marc Guillemot

    Marc Guillemot - 2010-03-11

    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.

     
  • Amit Manjhi

    Amit Manjhi - 2010-03-11

    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);

     

Log in to post a comment.