Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
ScheduledTaskStatistics.getLastRunDuration() returns negative values for quick executions #11929
I have reproduced it on my local workstation with a single member in cluster.
Looking at the code I can see that race-condition between updating lastRunStart/lastRunEnd fields and taking snapshot is possible:
In this case result of getLastRunDuration() operation would be negative
Sorry, cannot share any code from office.
Basically what I do is call schedule job at fixed rate R (say 1 minute) and immediately after that start a timer (vanila java Timer from JRE) with the same rate which calls IScheduledFuture.getStats() method
If my job takes a few seconds to execute, IScheduledFuture.getStats() called from Timer will get into race-condition described above and print the difference between lastRunEnd from previous execution and lastRunStart from current execution which is obviously negative