You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义ItemWriter中使用的ExecutionContext是Step还是Job执行上下文?

问题:自定义ItemWriter中update方法的ExecutionContext属于Step还是Job ExecutionContext?

我实现了一个自定义ItemWriter,使用ExecutionContext存储部分数据,现存在疑问:该ExecutionContext属于Step ExecutionContext还是Job ExecutionContext?我查阅了官方文档但未得到明确答案。相关代码如下:

public class SomeWriter extends ItemStreamSupport implements ItemWriter<Payment> {
    private int count = 0;
    @Override
    public void update(ExecutionContext executionContext) {
       executionContext.putInt("data1", count);
    }
}

答案

  • 你自定义的SomeWriter继承自ItemStreamSupport,ItemStream的update方法接收的ExecutionContext是Step级别的。
  • 核心原因:ItemStream是和Step的执行生命周期绑定的——Step启动时调用open、执行过程中/结束前调用update、结束时调用close,这些方法传递的都是当前Step对应的ExecutionContext。
  • 如果要操作Job级别的ExecutionContext,你需要通过StepExecution获取关联的JobExecution,进而拿到Job ExecutionContext。不过这没法直接在ItemStream的update方法里实现,通常可以通过StepListener或者在Step配置阶段注入相关对象来完成。

内容的提问来源于stack exchange,提问作者Prashant Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 12:54:57