Results 1 to 4 of 4

Thread: Job status is COMPLETED even after exception is thrown

  1. #1
    Join Date
    Dec 2010
    Posts
    175

    Default Job status is COMPLETED even after exception is thrown

    Hi,

    As of now, my job is configured to <batch:end on="FAILED"/> for step 1 and hence it completes with status COMPLETED if any exception occurs.

    I would like the job to end with FAILED status so that it can be restarted? should I remove <batch:end on="FAILED"/> and will it stop automatically after first failure and not move to next step?


    Code:
    Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [file:/C:/test.txt]
    	at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:250)
    	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:134)
    	... 26 more
    
    [SimpleAsyncTaskExecutor-2] ERROR org.springframework.batch.core.step.AbstractStep - Exception in afterStep callback
    java.lang.IllegalArgumentException: No records were loaded!
    	at org.springframework.util.Assert.isTrue(Assert.java:65)
    	at org.springframework.batch.core.listener.step.GenericStepExecutionListener.afterStep(GenericStepExecutionListener.java:37)
    	at org.springframework.batch.core.listener.CompositeStepExecutionListener.afterStep(CompositeStepExecutionListener.java:62)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:223)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    [SimpleAsyncTaskExecutor-2] INFO  org.springframework.batch.core.launch.support.SimpleJobLauncher - Job: [FlowJob: [name=loadFile]] completed with the following parameters: [{output.file=file:/C:/test503.TXT, input.file=file:/C:/test.TXT}] and the following status: [COMPLETED]

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    I would like the job to end with FAILED status so that it can be restarted? should I remove <batch:end on="FAILED"/> and will it stop automatically after first failure and not move to next step?
    yes. Any exception thrown in a step fails the step execution and then Spring Batch fails the job execution (this is the default).

  3. #3
    Join Date
    Dec 2010
    Posts
    175

    Smile

    Yes. It does that's what I meant when I said the batch status is set to COMPLETED. COMPLETED jobs cannot be restarted.

    Looking for answers to my question (while I try to figure out...)?

    Quote Originally Posted by arno View Post
    yes. Any exception thrown in a step fails the step execution and then Spring Batch fails the job execution (this is the default).

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    sorry if my previous answer wasn't clear enough (or if I don't get your question): if you remove <batch:end on="FAILED"/>, the job execution would have a FAILED status when an exception is thrown in the first step and you'll be able to restart the corresponding instance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •