Search code examples
javajakarta-eejava-ee-7jsr352

Stopping JobInstance through JobOperator


I'm trying to stop one job execution from a managedbean. More concretely, I'm able to get the job instance and stop the job instance as follows:

        JobOperator operator  = BatchRuntime.getJobOperator();
        List<Long> re = operator.getRunningExecutions("JobName");
        for (Long runningExecution: re) {
            operator.stop(runningExecution);
        } 

Even so, it doesn't take effect over the instance's execution that it continue running. In fact, if I try to get the job instance again it isn't possible because effectively method getRunningExecutions return no elements. In this manner, could anyone tell me what I'm doing wrong?

Thank you in advance.


Solution

  • getRunningExecutions returns empty since the job execution is probably in STOPPING status, and thus is not considering running executions any more.

    Try to call getBatchStatus() on each job execution to check the exact batch status. If your current step is a batchlet-type step, then the batchlet class should implement the stop() method to properly stop the work.