比较来自世界各地的卖家的域名和 IT 服务价格

Spring 批量 - 读取和处理了多少条记录

是否可以说出读取的记录有多少 / 或者在完全任务执行后处理? 我有一个作业,可以从数据库和处理器中读取数据,我将根据某些条件过滤几个条目,并将它们发送到编写器。 我想知道从中读取了多少条记录 DB 以及记录步骤的数量。

这是我的批处理配置文件。


<bean class="....JdbcCursorItemReader" id="dbItemReader">
<property name="datasource" ref="datasource"></property>
<property name="sql" ref="select * from"></property>
<property name="rowMapper">
<bean class="com.my.MyRowMapper"></bean>
</property>
</bean>
<bean class="com.my.MyItemProcessor" id="itemProcessor"></bean>
<bean class="com.my.MyItemWriter" id="itemWriter"></bean>
<batch:job id="myJob">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobTransactionManager">
<batch:chunk commit-interval="100" processor="itemProcessor" reader="dbItemReader" writer="itemWriter"></batch:chunk>
</batch:tasklet>


</batch:step></batch:job>
已邀请:

董宝中

赞同来自:

Spring 该包在任务存储中存储读取,处理,错过,录制等的元素数量。 假设您使用的是数据库任务存储库,您可以在表中查看它们。
BATCH_STEP_EXECUTION

.

有关存储在任务存储库中的信息的更多信息,您可以在此处读取文档:
http://docs.spring.io/spring-b ... .html

涵秋

赞同来自:

import org.apache.log4j.Logger;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
/**
* Vaquar khan
*/
public class StepExecuListner implements StepExecutionListener {
static Logger log = Logger.getLogger/"badRecordLogger"/;

@Override
public void beforeStep/StepExecution stepExecution/ {
System.out.println/"StepExecutionListener - beforeStep"/;
log.error/"StepExecutionListener - beforeStep " /;

}

@Override
public ExitStatus afterStep/StepExecution stepExecution/ {
System.out.println/"StepExecutionListener - afterStep"/;
log.error/"------------------------------------------------------------------------------------"/;
log.error/"StepExecutionListener - afterStep:getCommitCount=" + stepExecution.getCommitCount///;
log.error/"StepExecutionListener - afterStep:getFilterCount=" + stepExecution.getFilterCount///;
log.error/"StepExecutionListener - afterStep:getProcessSkipCount=" + stepExecution.getProcessSkipCount///;
log.error/"StepExecutionListener - afterStep:getReadCount=" + stepExecution.getReadCount///;
log.error/"StepExecutionListener - afterStep:getReadSkipCount=" + stepExecution.getReadSkipCount///;
log.error/"StepExecutionListener - afterStep:getRollbackCount=" + stepExecution.getRollbackCount///;
log.error/"StepExecutionListener - afterStep:getWriteCount=" + stepExecution.getWriteCount///;
log.error/"StepExecutionListener - afterStep:getWriteSkipCount=" + stepExecution.getWriteSkipCount///;
log.error/"StepExecutionListener - afterStep:getStepName=" + stepExecution.getStepName///;
log.error/"StepExecutionListener - afterStep:getSummary=" + stepExecution.getSummary///;
log.error/"StepExecutionListener - afterStep:getStartTime=" + stepExecution.getStartTime///;
log.error/"StepExecutionListener - afterStep:getStartTime=" + stepExecution.getEndTime///;
log.error/"StepExecutionListener - afterStep:getLastUpdated=" + stepExecution.getLastUpdated///;
log.error/"StepExecutionListener - afterStep:getExitStatus=" + stepExecution.getExitStatus///;
log.error/"StepExecutionListener - afterStep:getFailureExceptions=" + stepExecution.getFailureExceptions///;
log.error/"------------------------------------------------------------------------------------"/;

return null;
}
}


在派对内 xml


<bean class="com.test.listener.StepListner" id="stepListener"></bean>
<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 commit-interval="${commitInterval}" reader="itemReader" skip-limit="3" writer="itemWriter">
<batch:skippable-exception-classes>
<batch:include class="java.lang.NumberFormatException"></batch:include>
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener"></batch:listener>
<batch:listener ref="stepListener"></batch:listener>
</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 commit-interval="${commitInterval}" reader="itemReaderToDelete" skip-limit="3" writer="itemWriterToDelete">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.dao.DataAccessException"></batch:include>
<batch:include class="java.lang.NumberFormatException"></batch:include>
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="skipListener"></batch:listener>
<batch:listener ref="stepListener"></batch:listener>
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
</batch:split>
</batch:job>

二哥

赞同来自:

最简单的方法 - 您可以在步骤中使用侦听器,您可以获得所有计数。


<batch:job id="myJob">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobTransactionManager">
<batch:chunk commit-interval="100" processor="itemProcessor" reader="dbItemReader" writer="itemWriter">
<bean class="com.company.listner.StepListner" id="customStepListner"></bean>
</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/ {

}
}


</batch:step></batch:job>

要回复问题请先登录注册