【问题标题】:How to restart a spring boot batch job by jobId如何通过 jobId 重新启动 Spring Boot 批处理作业
【发布时间】:2018-01-24 09:43:36
【问题描述】:

我曾经搜索过这个问题,一些代码是这样的:

JobOperator jobOperator = BatchRuntime.getJobOperator();

        jobOperator.stop(Long jobId);

但是在作业运行时我找不到jobId。

你有什么想法吗?谢谢

【问题讨论】:

  • 你的工作声明怎么样。放代码
  • JobParameters jobParameters = new JobParametersBuilder() .addLong("time", System.currentTimeMillis()) .addString("topicId", topicId) .addString("appId", appId) .toJobParameters() ; JobExecution run = jobLauncher.run(etlJob, jobParameters)

标签: spring-boot spring-batch


【解决方案1】:

我已经解决了这个问题。

public class StepExecutionListener implements org.springframework.batch.core.StepExecutionListener {

    @Override
    public void beforeStep(StepExecution stepExecution) {
        JobExecution jobExecution = stepExecution.getJobExecution();
        Long id = jobExecution.getId();
        JobParameters jobParameters = jobExecution.getJobParameters();
        String topicId = jobParameters.getString("topicId");
        String appId = jobParameters.getString("appId");
        JobHelper.jobIdMap.put(topicId + appId, id);
    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        return null;
    }
}

,我们需要在步骤中添加监听器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2014-05-30
    • 2023-04-08
    相关资源
    最近更新 更多