I'm writing a jBatch program with jBeret. I am currently doing like this.
final JobOperator operator = BatchRuntime.getJobOperator();
logger.debug("operator: {}", operator);
final long id = operator.start("some", null);
logger.debug("id: {}", id);
final JobExecution execution = operator.getJobExecution(id);
logger.debug("execution: {}", execution);
The problem is that execution seems run asynchronously and the main method simply returns.
The best I can do is looping until exit status is not null.
String status;
while ((status = execution.getExitStatus()) == null) {
//logger.debug("sleeping");
Thread.sleep(1000L);
}
logger.debug("status: {}", status);
Is there any other way to do this?
If you need to
block-and-wait
, as you've described, there is no other option, but have something likeawaiCompletion()
implemented.Your looping approach can be improved. Let's use
ThreadPoolExecutor
as an example. It has the following method:and here is the implementation:
Please note:
So, here is an adapted version: