Failed to restart Spring batch job

I have a spring batch job that reads, converts and writes to an Oracle database. I do the work using the CommandLineJobRunner utility (using the jar + fat dependencies generated with the maven shade plugin); the job subsequently failed halfway due to the "reached java heap memory limit", and the job is not marked as "FAILED", but still shows STARTED status.

I tried to restart the task using the same working parameters (as the docs suggest), but this gives me this error:

5:24:34.147 [main] ERROR osbclsCommandLineJobRunner - Job Terminated in error: A job execution for this job is already running: JobInstance: id=1, version=0, Job=[maskTableJob] 

org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: The job for this job is already running: JobInstance: id = 1, version = 0, Job = [maskTableJob] on org.springframework.batch.core.repository.support.SimpleJobRepository. createJobExecution (SimpleJobResository.java:120) ~ [maskng-batch-1.0-SNAPSHOT-executable.jar: 1.0-SNAPSH

I tried all kinds of things (for example, manually setting the status to FAILED using the -restart argument), but to no avail. Something I'm missing here, because I thought one of the strengths of the spring package is its ability to restart jobs where they left off .... !!?

+1
source share
1 answer

The first thing you should know is Joblauncher, which cannot be used to restart an already running job. The reason you get a "JobExecutionAlreadyRunningException" is because the parameter that you are passing is already in the database and therefore you are getting this exception.

In the spring package, the task can be restarted if it is completed with the status "FAILED" or "STOPPED".

JobOperator has a reload method that you can use to restart a failed job by passing a run identifier that has been filled with the status "FAILED" or "STOPPED".

Please note that the task cannot be restarted if it is completed with the status "FINISHED". In this case, you will need to send a new task with new task parameters

If you want to manually set the status of the job as a failure, run the query below and restart the job using the JobOperator.restart () method.

 update batch_job_execution set status="FAILED", version=version+1 where job_instance_id=jobId; 

Incorrect transaction management processing may be one of the possible reasons why the status of your work is not updated with the status β€œFAILED”. Verify that the transaction has completed even if the job encountered a run-time exception.

+2
source

All Articles