I have a web application that creates jobs periodically. This web app is on a server and works fine. If the server crashes and then restarts, the JobExplorer
shows that job is still running. But in fact that job never stops and I have to stop it myself. To do so, I am trying to use the JobOperator
and the funny thing is it says it cannot stop a job that is not running.
To get a list of running jobs:
for (String jn : jobExplorer.getJobNames())
for (JobExecution je : jobExplorer.findRunningJobExecutions(jn)) {
...
}
To stop a job:
try {
jobOperator.stop(je.getId());
} catch (NoSuchJobExecutionException e1) {
e1.printStackTrace();
} catch (JobExecutionNotRunningException e1) {
e1.printStackTrace();
}
The error message is "JobExecution must be running so that it can be stopped"
Both je.isRunning()
and je.isStopping()
return true.