首页 > 解决方案 > 为什么在 Spring Cloud Data Flow 中启动后没有销毁任务?

问题描述

我创建了一些 Spring Batch 项目并使用 Spring Cloud Data Flow (SCDF) 部署这些作业。
在 SCDF 中启动任务(作业)后,它会创建 JVM 来执行任务(作业)。
但是,当任务完成时,那个 JVM 并没有结束。它仍然存在。
当我启动我的工作 20 次时,它宣布

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

还有一些关于我的工作的信息,工作的第一个日志以:

HikariPool-1 - Shutting down...

但是在我为 Spring Batch 项目使用了以下属性之后:

spring.cloud.task.singleInstanceEnabled=true

并使用 afterJob 方法通过使用 JobExecutionListenerSupport 任务(job)的日志以:

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}

我的 Spring Batch Job 有这些问题吗?

我的主要问题是哪个负责完全停止 JVM(任务)?Spring Cloud Data Flow 部分或 Spring Batch 部分以及如何?

我认为当任务完成时,它应该被销毁(JVM停止)并且并发任务执行的数量不能达到限制。

标签: springspring-batchspring-cloud-dataflow

解决方案


我从 github 获得了设置属性的解决方案spring.cloud.task.closecontext_enabled = true。但是我想深入了解没有spring.cloud.task.closecontext_enabled上下文没有完全关闭的原因。将该属性设置为 true 后。我的 Spring Batch 项目的日志显示了 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

还有 ItemReader 代码:

@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;  
}

推荐阅读