Why is my Spring Batch job not exiting after completion

眉间皱痕 提交于 2020-03-25 18:07:52

问题


My batch job is configured as follows

@Bean("MyJob")
    public Job umpInpatientCensusRptBatchJob(...) throws IOException {
        return jobBuilderFactory.get( "MyJob" )
                .incrementer( new RunIdIncrementer() )
                .start( Step0 ).on( COMPLETE ).end()
                .from( Step0 ).on( CONTINUE )
                .to( Step1 )
                .next( Step2 )
                .next( Step3 )
                .end()
                .build();
    }

where Steps 0, 1, and 3 are tasklets. My Job is completing with the message Job: [FlowJob: [name=MyJob]] completed with the following parameters. However, it doesn't exit - it hangs there. When I run it locally on IntelliJ, I have to manually quit the job.

I haven't implemented any asynchronicity. Each tasklet is also explicitly returning a FINISHED status upon completion.


回答1:


An apparent problem is the word "COMPLETE" inside the first on(). The method on(String pattern) is given "COMPLETE" as a parameter instead of, for example, "COMPLETED", the job completes with a FAILED state, if an appropriate custom exit status hasn't been created. However, I don't know why it hangs and doesn't just fail in your case. The following version of your job configuration seems to run fine, as long as all the tasklets return a FINISHED RepeatStatus:

@Bean("MyJob")
public Job umpInpatientCensusRptBatchJob(...) throws IOException {
    return jobBuilderFactory.get( "MyJob" )
            .incrementer( new RunIdIncrementer() )
            .start( Step0 ).on( "COMPLETED" ).end()
            .from( Step0 ).on( "CONTINUE" )
            .to( Step1 )
            .next( Step2 )
            .next( Step3 )
            .end()
            .build();
}

If the tasklet of Step0 returns RepeatStatus.CONTINUABLE though, Step0 repeats forever, since that is the purpose of that RepeatStatus. So, it's impossible to reach Step1 with this configuration. In order to decide if you should run the next steps, instead of using the tasklet repeat status (which I don't know if is possible) you could either use a StepExecutionListener on Step0 or add a decider to the flow, after Step0:

Spring-Batch: how do I return a custom Job exit STATUS from a StepListener to decide next step



来源:https://stackoverflow.com/questions/59814193/why-is-my-spring-batch-job-not-exiting-after-completion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!