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.