[英]Spring Batch. How to limit the no of executions of a chunk
我最近开始使用弹簧批。 任何正文都可以告诉我如何在tasklet中限制块的执行次数(即调用ItemReader和ItemWrite)。
我在tasklet中设置了allow-start-if-complete =“false”,start-limit =“1”。 然后我在块中设置commit-interval =“1”。
<batch:step id="mig-chain-data">
<batch:tasklet allow-start-if-complete="false" start-limit="1">
<batch:chunk commit-interval="1" reader="reader" writer="writer"></batch:chunk>
</batch:tasklet>
</batch:step>
我的期望是每次批处理作业执行只运行一次tasklet / chunk。 但是行为是块(读者和作者)被多次/无限地调用。
请有人帮我解决这个问题。
块的执行次数取决于reader
; Spring Batch无法控制它。 如果您的读者从数据库表中读取,则此限制将是从SQL语句返回的记录数,或者如果它从文件中读取它将是行数(在非常基本的情况下)
start-limit
控制Step可以启动的次数,而不是为此步骤配置的chunk。
在您自己的阅读器中添加两个参数:
private static int numberOfReading=0;
@Value("${batch.maxNumberOfReading}")
private int maxNumberOfReading;
并且在read方法中使用此变量来控制流程:
if(numberOfReading<maxNumberOfReading){
// do what do yoou have to do
numberOfReading++;
// return the result to the writer
}
return null;
batch.maxNumberOfReading在属性文件中设置,值为1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.