2

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.

Hamed
  • 1,175
  • 3
  • 20
  • 46
  • `But in fact that job never stops and I have to stop it myself`: Can you explain how is the job still running when the server craches? Is the job running in the same JVM as the webapp or in a separate JVM? – Mahmoud Ben Hassine Apr 04 '19 at 07:48
  • 1. When the server crashes, it restarts automatically. When it boots up again the state of the job is running. 2. They are both on the same JVM – Hamed Apr 04 '19 at 17:52
  • In this case, you need to update the job status manually in the job repository. Please see: https://stackoverflow.com/questions/53645178/ – Mahmoud Ben Hassine Apr 05 '19 at 08:07
  • @MahmoudBenHassine I set `e.setStatus(BatchStatus.FAILED)` and `e.setExitStatus(ExitStatus.FAILED)` and then called `jobOperator.stop(je.getId());` Still the status is STOPPING and the job is listed as Running – Hamed Apr 12 '19 at 20:36

0 Answers0