在spring批处理中,所有分区步骤共享相同的itemwriter侦听器?

时间:2014-04-02 18:46:40

标签: spring-batch

我有这样的配置

<batch:chunk writer="itemWriter" reader="itemReader" commit-interval="1000" />
        <batch:listeners>
            <batch:listener ref="MyWriterListener" />
        </batch:listeners>

我想知道在对资源进行分区后,每个并行步骤共享相同的MyWriterListener?

这是听众

public class MyVehiclesWriterListener implements ItemWriteListener<PurchasedVehicleModel>, StepExecutionListener {

private static final String FILE_NAME = "fileName";

private StepExecution stepExecution;

@Override
public void beforeWrite(List<? extends PurchasedVehicleModel> items) {
    //s_logger.log(LogLevel.WARN, stepExecution.getId() + " The processed file name is " + stepExecution.getExecutionContext().getString(FILE_NAME));
}

@Override
public void afterWrite(List<? extends PurchasedVehicleModel> items) {

    log(LogLevel.WARN, " Step Id : " + stepExecution.getId());
}

@Override
public void onWriteError(Exception exception, List<? extends PurchasedVehicleModel> items) {
}

@Override
public void beforeStep(StepExecution currentStepExecution) {
    log(LogLevel.WARN, " Step Id : " + currentStepExecution.getId());
    stepExecution = currentStepExecution;
}

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    return null;
}

}

在afterWrite函数中,我只能获得相同的步执行ID。

但在beforeStep函数中,我可以获得不同的ID。

0 个答案:

没有答案