Fazil Hussain
Fazil Hussain

Reputation: 425

JSR 352: Is there a way to tell if a particular job execution is a restart or not from within a job?

I know how to get the Execution Id and Instance Id of a job using the Job Context. But if i restart a job, is there way to know if the job execution is the first execution or a restart within the job, for instance inside the reader?

Upvotes: 3

Views: 510

Answers (2)

Scott Kurz
Scott Kurz

Reputation: 5320

This is a bit overly complicated (as the other answer noted, there's an issue opened to consider enhancement for the future Batch 1.1).

You could do this:

//
// Assumes JobContext injected into 'jobCtx' field
//
private boolean isRestart() {
    JobOperator jo = BatchRuntime.getJobOperator();
    JobInstance jobInstance = jo.getJobInstance(jobCtx.getExecutionId());
    int numExecutions = jo.getJobExecutions(jobInstance).size();
    return numExecutions > 1;
}

Upvotes: 2

DFollis
DFollis

Reputation: 419

No, but there is an open issue asking for that: https://java.net/bugzilla/show_bug.cgi?id=7473

Upvotes: 2

Related Questions