2

我正在尝试运行面向分区的作业并且在访问 stepExecutionContext 存储的数据时遇到了麻烦。这是我的工作定义

<batch:job id="job1" restartable="false" incrementer="idIncrementer">
    <batch:step id="readwritestep" next="partitionStep">
        <batch:tasklet transaction-manager="transactionManager">
            <batch:chunk reader="reader1"
                         writer="writer1"
                         commit-interval="500"/>
        </batch:tasklet>
        <batch:listeners>
            <batch:listener ref="promotionListener"/>
        </batch:listeners>
    </batch:step>
    <batch:step id="partitionStep" >
        <batch:partition step="detailsStep" partitioner="partitioner">
            <batch:handler grid-size="10" task-executor="taskExecutor" />
        </batch:partition>
    </batch:step>
</batch:job>
<batch:step id="detailsStep">
    <batch:tasklet transaction-manager="transactionManager">
        <batch:chunk reader="reader2"
                         processor="processor"
                         writer="writer2"
                         commit-interval="1500"/>
    </batch:tasklet>
</batch:step>

在处理 readwritestep 时,我将一些数据存储在 step 上下文中并提升到 job 上下文,以便我可以在 partioner 中访问。但是我已经实现的自定义分区器没有任何对父步骤的引用,我可以在其中访问存储的数据......即使分区器绑定到 STEP,它也无法访问父步骤数据......我在这里遗漏了什么吗?分区器提供的一个选项是 jdbctemplate 来生成我不感兴趣的拆分器上下文。我试图注入 @beforestep 注释来访问上下文数据,但它没有被调用..我不想执行 JDBC 读取来生成从属数据...我想获取存储在步骤中的 LIST 数据/作业上下文执行并生成拆分器上下文...有人可以帮我指出正确的方向,以便我可以访问该数据...

这是分区类...

     public class ProductDetailsPartitioner implements Partitioner {

     private List<Product> prds;


      @Override
      public Map<String, ExecutionContext> partition(int gridSize) {
       List<String> referencIds = new ArrayList<String>();
       for (Product prd : prds) {
        referencIds.add(prd.getReferenceId());
       }
       Map<String, ExecutionContext> results = new LinkedHashMap<String,ExecutionContext>();
      for (String referencId : referencIds) {
        ExecutionContext context = new ExecutionContext();
        context.put("referenceId", referencId);
        results.put("partition." + referencId, context);
      }
        return results;
    }

     @BeforeStep
     public void retrieveInterstepData(StepExecution stepExecution) {
           System.out.println("Entered Before step in partion");
           JobExecution jobExecution = stepExecution.getJobExecution();
           ExecutionContext jobContext = jobExecution.getExecutionContext();
           System.out.println("ExecutionContext"+jobContext);
           this.prds = (List<Product>) jobContext.get("products");

     }
  }
4

1 回答 1

0

好的,我可以通过另一种方法解决这个问题。现在我正在处理基于 jobid 的partioner,而不是通过执行上下文传递引用。它运行良好。很难解释真正的解决方案,因为它是基于真实的业务需求。

于 2013-02-09T00:17:24.843 回答