I am trying to create a monitor that will generate an alert when a scheduled task has been running too long. By calling:
com.wm.app.b2b.server.scheduler.ScheduledTask  schTasks = com.wm.app.b2b.server.scheduler.ScheduleManager.getTasks();
I get all the scheduled tasks and find the ones that are running. By comparing scheduledTask.getNextRun() to the current time I was hoping to determine if the task was supposed to have run but has not because the previous instance is still running. Then using the scheduledTask.getInterval() I can determine how bad it is and whether or not to generate a minor or a major alert.
Unfortunately when I test it using a scheduled service that simply sleeps (calls Thread.sleep(n)), the getNextRun() always returns a future time and is different every time. I would expect that a scheduled service that is scheduled to run say every 30 seconds and has been running for several minutes without ending, to get the same getNextRun() until it ends and starts again. Is my expectation incorrect? Is there a better way to monitor for a runaway scheduled service?