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」 –