0

I am looking for a best approach in determining if a spring batch job has completed that does not involve using a job listener. I am using the jsr compliant components. The reason for no job listener is I do not want to be dependent on the end user defining their job correctly to include the listener.

The only approach I have come up with so far is to put this in the class that is calling the start/restart

        executionID = jobOperator.start(jobName, properties);

        BatchStatus status = jobOperator.getJobExecution(executionID).getBatchStatus();
        while(status != BatchStatus.ABANDONED && status != BatchStatus.COMPLETED && status != BatchStatus.FAILED &&
                status != BatchStatus.STOPPED){
            Thread.sleep(1000);
            status = jobOperator.getJobExecution(executionID).getBatchStatus();
        }

The issue I have here is this queries the db and on a fairly long running job this could query the db thousands of times getting the status. It seems there should be a better approach. That some where in memory that the operator or some other object would have the current status of a job with out having to go to the db. Or possibly a way to do a callback with out having to define it in the job spec.

Mark Kouba
  • 236
  • 2
  • 12

1 Answers1

0

How about putting your Job Listener to the parent job XML and inherit it from all of your job XMLs? Something like early part of this example: https://blog.codecentric.de/en/2013/06/spring-batch-2-2-javaconfig-part-4-job-inheritance/

Putting Job Listener to all of job XMLs seem to be easily missed, but I think setting parent job XMLs are better and easy to maintain.

Kohei Nozaki
  • 1,154
  • 1
  • 13
  • 36
  • I tried this but it does not seem to work with the JSR compliant launcher and so on. I'm guessing this feature is just available for pure spring batch? It would be a great idea if it did work though. – Mark Kouba Sep 14 '15 at 13:49
  • I double checked the JsrJobParser class and it does not support that attribute only the JobParser does. – Mark Kouba Sep 14 '15 at 15:00