Java Spring批处理并行Seam上下文,没有活动的应用程序上下文
我正在尝试并行处理Spring批处理作业中的一些步骤。作业的XML配置如下所示:Java Spring批处理并行Seam上下文,没有活动的应用程序上下文,java,parallel-processing,spring-batch,seam2,Java,Parallel Processing,Spring Batch,Seam2,我正在尝试并行处理Spring批处理作业中的一些步骤。作业的XML配置如下所示: <batch:job id= "job" job-repository = "jobRepository"> <batch:split id="split" task-executor="taskExecutor"> <batch:flow> <batch:step id = "step1"> <batch:tasklet
<batch:job id= "job" job-repository = "jobRepository">
<batch:split id="split" task-executor="taskExecutor">
<batch:flow>
<batch:step id = "step1">
<batch:tasklet transaction-manager = "txManager" >
<batch:chunk reader = "reader1"
processor = "processor1"
writer = "writer1"
commit-interval = "1" />
</batch:tasklet>
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id = "step2">
<batch:tasklet transaction-manager = "txManager">
<batch:chunk reader = "reader2"
processor = "processor2"
writer = "writer2"
commit-interval = "1" />
</batch:tasklet>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>
taskExecutor是一个SimpleSyncTaskExecutor
在区块中,我使用的是读卡器、处理器和写入器。这些都取决于接缝(2.2.2)
当这些步骤在单线程模式下运行时,它们都可以正常工作。但当它们并行运行时,会导致错误,因为没有可用的Seam上下文。显然是因为创建了一个新线程,并且没有启动Seam生命周期(lifecycle.beginCall())
如何确保在处理区块时启动生命周期?我真的不想在读卡器中启动生命周期并在写卡器中结束它,但它应该在执行tasklet时启动,在tasklet完成时结束。在执行步骤之前启动上下文:
<batch:step id="step1">
<batch:tasklet>
<batch:chunk ...>
</batch:chunk>
</batch:tasklet>
<batch:listeners>
<batch:listener ref="stepExecutionListener"/>
</batch:listeners>
</batch:step>
public abstract class MyStepExecutionListener implements StepExecutionListener {
@Override
public void beforeStep(StepExecution stepExecution) {
Lifecycle.beginCall();
}
/**
* Default no-op implementation.
* @return ExitStatus of step.
*/
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
return stepExecution.getExitStatus();
}
}