0
我正在使用Spring Batch,并创建了一个使用SimpleAsyncTaskExecutor
运行的tasklet。在这一步,我检索StepExecutionContext
与在Spring批处理中的多线程步骤中写入StepExecutionContext
@BeforeStep
public void saveStepExecution(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
在微进程的处理方法,我尝试更新的背景:
stepExecution.getExecutionContext().put("info", contextInfo);
这导致ConcurrentModificationException
S于该stepExecution
。 如何避免这些并在此多线程环境中更新我的上下文?
请提供更多信息,例如其中spring批处理版本和tasklet实现的来源 –
SpringBatch 2.1.8。你需要回答这个问题需要哪些细节? – tobiasbayer
如果您使用'org.springframework.batch.core.step.tasklet.Tasklet'实现了一个tasklet,那么您需要实现'RepeatStatus execute(StepContribution贡献,ChunkContext chunkContext)'并且chunkContext里面是一个可修改的stepExecutionContext,您可以使用BeforeStep注解获得stepExecution,所以我不确定你的“tasklet”是什么样子,或者它甚至是“Tasklet” –