springspring-batchspring-cloud-dataflow

Why tasks are not destroyed after launching in Spring Cloud Data Flow?


I have create some Spring Batch Project and deploy these Job by using Spring Cloud Data Flow (SCDF).
After Launching task(job) in SCDF, it create JVM to execute the task(job).
However when the task is finished, that JVM is not end. It still existed.
When I launch my job 20 times, it announced that

Cannot launch task A. The maximum concurrent task executions is at its limit [20]

And there are some information about my Job, the first log of the jobs is end with:

HikariPool-1 - Shutting down...

But after I used a below property for the Spring Batch Project:

spring.cloud.task.singleInstanceEnabled=true

and used afterJob method by using JobExecutionListenerSupport The log of the task(job) end with:

o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=remindJob]] completed with the following parameters: [{run.id=3}] and the following status: [COMPLETED] in 7s636ms
o.s.integration.leader.DefaultCandidate  : DefaultCandidate{role=EngineProcess, id=126} leadership has been revoked: LockContext{role=Process, id=126, isLeader=false}

Are these any problems with my Spring Batch Job?

And my major question is that which one is responsible for completely stopping JVM(task)? Spring Cloud Data Flow part or Spring Batch part and how?

I think that when task are finished, it should be destroyed (JVM is stopped) and the number of concurrent task executions could not be at the limit.


Solution

  • I got the solutions from github that setting the property spring.cloud.task.closecontext_enabled = true. However I would like to understand deeply the reason why the context is not closed completely without spring.cloud.task.closecontext_enabled. After setting that property to true. My Spring Batch project's log showed the WARN:

    main] o.s.b.f.support.DisposableBeanAdapter : Destroy method 'close' on bean with name 'getStudent' threw an exception: org.springframework.batch.item.ItemStreamException: Error while closing item reader
    

    And there is the ItemReader code:

    @Bean
    public JdbcCursorItemReader<Student> getStudent() {
        JdbcCursorItemReader <Student> reader = new JdbcCursorItemReader<>();
        reader.setDataSource(dataSource);
        reader.setSql(QueryConstants.getStudent);   
        reader.setRowMapper(new BeanPropertyRowMapper<>(Student.class)); 
        return reader;  
    }