Spring Batch-读取多少条记录&;处理
一旦作业完全执行,是否可以告知读取和/或处理了多少记录?我有一个任务,从数据库中读取数据,在处理器中,我根据某些条件过滤一些记录,并将它们发送给编写器。我想知道从数据库中读取了多少条记录,以及有多少条记录被发送到writer步骤 这是我的批处理配置文件Spring Batch-读取多少条记录&;处理,spring,spring-batch,Spring,Spring Batch,一旦作业完全执行,是否可以告知读取和/或处理了多少记录?我有一个任务,从数据库中读取数据,在处理器中,我根据某些条件过滤一些记录,并将它们发送给编写器。我想知道从数据库中读取了多少条记录,以及有多少条记录被发送到writer步骤 这是我的批处理配置文件 <bean id="dbItemReader" class="....JdbcCursorItemReader"> <property name="datasource" ref="datasource"/>
<bean id="dbItemReader" class="....JdbcCursorItemReader">
<property name="datasource" ref="datasource"/>
<property name="sql" ref="select * from"/>
<property name="rowMapper">
<bean class="com.my.MyRowMapper"/>
</property>
</bean>
<bean id="itemProcessor" class="com.my.MyItemProcessor"/>
<bean id="itemWriter" class="com.my.MyItemWriter"/>
<batch:job id="myJob">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobTransactionManager">
<batch:chunk reader="dbItemReader" processor="itemProcessor" writer="itemWriter" commit-interval="100"/>
</batch:tasklet>
Spring Batch在作业存储库中存储读取、处理、跳过、写入等项的数量。假设您使用的是数据库作业存储库,您可以在
BATCH\u STEP\u EXECUTION
表中查看它们
您可以在此处的文档中阅读有关存储在作业存储库中的信息的更多信息:最简单的方法是-您可以在步骤中使用侦听器并获取所有计数
<batch:job id="myJob">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobTransactionManager">
<batch:chunk reader="dbItemReader"
processor="itemProcessor"
writer="itemWriter"
commit-interval="100">
<bean id="customStepListner" class="com.company.listner.StepListner" />
</batch:chunk>
</batch:tasklet>
public class StepListner implements StepExecutionListener {
@Override
public ExitStatus afterStep(StepExecution arg0) {
int readCount=arg0.getReadCount();
int writeCount=arg0.getWriteCount();
int skipCount=arg0.getSkipCount();
int commitCount=arg0.getCommitCount();
arg0.getStartTime();
arg0.getEndTime();
}
@Override
public void beforeStep(StepExecution arg0) {
}
}
公共类StepListner实现StepExecutionListener{
@凌驾
公共退出状态后步骤(步骤执行arg0){
int readCount=arg0.getReadCount();
int writeCount=arg0.getWriteCount();
int skipCount=arg0.getSkipCount();
int commitCount=arg0.getCommitCount();
arg0.getStartTime();
arg0.getEndTime();
}
@凌驾
预处理前的公共无效(步骤执行arg0){
}
}
批处理xml的内部
<bean id="stepListener" class="com.test.listener.StepListner" />
<batch:job id="TestDataLoader">
<batch:split id="split1" task-executor="taskExecutor">
<batch:flow>
<batch:step id="step1">
<batch:tasklet task-executor="taskExecutor" throttle-limit="5">
<batch:chunk reader="itemReader" writer="itemWriter" commit-interval="${commitInterval}" skip-limit="3">
<batch:skippable-exception-classes>
<batch:include class="java.lang.NumberFormatException" />
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener" />
<batch:listener ref="stepListener" />
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="step2">
<batch:tasklet task-executor="taskExecutor" throttle-limit="15">
<batch:chunk reader="itemReaderToDelete"
writer="itemWriterToDelete" commit-interval="${commitInterval}" skip-limit="3">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.dao.DataAccessException" />
<batch:include class="java.lang.NumberFormatException" />
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener" />
<batch:listener ref="stepListener" />
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>
我正在使用内存中的元数据工厂-MapJobRepositoryFactoryBean。在这种情况下,有没有办法获得这些详细信息?只有在同一个JVM运行时才有。
<bean id="stepListener" class="com.test.listener.StepListner" />
<batch:job id="TestDataLoader">
<batch:split id="split1" task-executor="taskExecutor">
<batch:flow>
<batch:step id="step1">
<batch:tasklet task-executor="taskExecutor" throttle-limit="5">
<batch:chunk reader="itemReader" writer="itemWriter" commit-interval="${commitInterval}" skip-limit="3">
<batch:skippable-exception-classes>
<batch:include class="java.lang.NumberFormatException" />
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener" />
<batch:listener ref="stepListener" />
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="step2">
<batch:tasklet task-executor="taskExecutor" throttle-limit="15">
<batch:chunk reader="itemReaderToDelete"
writer="itemWriterToDelete" commit-interval="${commitInterval}" skip-limit="3">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.dao.DataAccessException" />
<batch:include class="java.lang.NumberFormatException" />
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener" />
<batch:listener ref="stepListener" />
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>