带有调度程序的简单Spring Batch作业:第一次迭代成功。后续迭代失败

痛手指

通过STS提供Simple Spring Batch Project尝试了Spring Batch 我添加了Spring的调度功能,并使用PostgreSQL来存储元数据。

我使用一个简单的配置以及ItemReader和ItemWriter的示例实现,如下所示。作业定义为每15秒运行一次。尽管在第一次迭代中一切正常,但在后续迭代中似乎跳过读写操作

这是作业配置:

<batch:job id="job1">
    <batch:step id="step1">
        <batch:tasklet start-limit="100" transaction-manager="transactionManager">
            <batch:chunk reader="reader" writer="writer"
                commit-interval="1" />
        </batch:tasklet>
    </batch:step>
</batch:job>

<!-- Run every 15 seconds -->
<task:scheduled-tasks>
    <task:scheduled ref="testTask" method="run"
        cron="*/15 * * * * *" />
</task:scheduled-tasks>

在这里您可以看到我的读者和作家:

@Component("reader")
public class ExampleItemReader implements ItemReader<String> {

    private String[] input = {"Hello world!","Wow!", "Thats","cool!",null};
    private int index = 0;

    public String read() throws Exception {
        if (index < input.length) {
            return input[index++];
        }
        else {
            return null;
        }
     }
}

@Component("writer")
public class ExampleItemWriter implements ItemWriter<Object> {

     public void write(List<? extends Object> data) throws Exception {
           System.out.println("data: " + data);
     }
}

这是迭代1和2的控制台输出:

<Job: [FlowJob: [name=job1]] launched with the following parameters: [{date=Fri Dec 20 17:00:15 CET 2013}]>
<Job execution starting: JobExecution: id=18, version=0, startTime=null, endTime=null, lastUpdated=Fri Dec 20 17:00:15 CET 2013, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=18, version=0,JobParameters=[{date=Fri Dec 20 17:00:15 CET 2013}], Job=[job1]]>
<Resuming state=job1.step1 with status=UNKNOWN>
<Handling state=job1.step1>
<Executing step: [step1]>
<Executing: id=18>
<Starting repeat context.>
<Repeat operation about to start at count=1>
<Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@33f487e7>
<Chunk execution starting: queue size=0>
<Starting repeat context.>
<Repeat operation about to start at count=1>
<Repeat is complete according to policy and result value.>
<[Hello world!]>
<Inputs not busy, ended: false>
<Applying contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]>
<Saving step execution before commit: StepExecution: id=18, version=1, name=step1, status=STARTED, exitStatus=EXECUTING, readCount=1, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=>


... output of other chunks ommitted ...


<Repeat is complete according to policy and result value.>
<Step execution success: id=18>
<Step execution complete: StepExecution: id=18, version=7, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=4, filterCount=0, writeCount=4 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=5, rollbackCount=0>
<Completed state=job1.step1 with status=COMPLETED>
<Handling state=job1.end1>
<Completed state=job1.end1 with status=COMPLETED>
<Job execution complete: JobExecution: id=18, version=1, startTime=Fri Dec 20 17:00:15 CET 2013, endTime=null, lastUpdated=Fri Dec 20 17:00:15 CET 2013, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=18, version=0, JobParameters=[{date=Fri Dec 20 17:00:15 CET 2013}], Job=[job1]]>
<Job: [FlowJob: [name=job1]] completed with the following parameters: [{date=Fri Dec 20 17:00:15 CET 2013}] and the following status: [COMPLETED]>
Exit Status : COMPLETED

到目前为止,我不知道是什么会导致这种行为。我希望你们中的每个人都能告诉我该怎么做,以使阅读和写作可以在任何迭代中进行!

先感谢您!

痛手指

帕维尔·霍拉尔(Pavel Horal)

您的读者是单身人士,但应该是@Scope("step")在后续运行中,if (index < input.length)条件始终为假。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Return 语句打印第一次迭代,而 Print 输出所有迭代 - Python

来自分类Dev

Foreach循环在第一次迭代中绑定所有数据

来自分类Dev

Foreach循环在第一次迭代中绑定所有数据

来自分类Dev

如果在第一次迭代和第二次迭代之间有一小段时间

来自分类Dev

仅一次迭代,应用程序便崩溃了。没有可运行的设备,它根本无法运行。现在它在第一次迭代后崩溃

来自分类Dev

为什么带有select的菜单第一次失败?

来自分类Dev

Firebase调度功能在第一次调度后失败

来自分类Dev

是否有一种干净的方法可以仅在第一次迭代时或在执行之前检查循环中的变量?

来自分类Dev

为什么在使用 node 和 redis 时我的承诺没有解决?我的数组返回第一次迭代而不是等待整个代码运行

来自分类Dev

广度第一次迭代?

来自分类Dev

广度第一次迭代?

来自分类Dev

遍历数组对象以检查值是否匹配仅适用于第一次迭代,后续迭代失败

来自分类Dev

从表单添加和删除元素,第一次单击有效,后续单击不起作用

来自分类Dev

在 dplyr 中使用 filter() 查找第一次出现的 grepl 值并返回它和所有后续行

来自分类Dev

Pandas:如何在第一次满足条件后删除组的所有后续行?

来自分类Dev

应用程序内购买第一次使用沙箱失败,下次工作正常

来自分类Dev

Spring Cloud Hystrix在第一次命令调用时失败

来自分类Dev

twitter小部件仅在第一次加载时有效,然后失败

来自分类Dev

在一次迭代中显示带有Jtextarea的arraylist?

来自分类Dev

PowerShell中的ForEach循环在第一次迭代后失败

来自分类Dev

Spring Boot 作业调度程序

来自分类Dev

第一次关闭所有子菜单

来自分类Dev

第一次出现的变量有值吗?

来自分类Dev

GridView第一次没有被点击

来自分类Dev

Favicon第一次没有出现

来自分类Dev

钩子第一次没有设置状态

来自分类Dev

javascript没有看到第一次点击?

来自分类Dev

GridView第一次没有被点击

来自分类Dev

getElementById 仅在第一次有效

Related 相关文章

  1. 1

    Return 语句打印第一次迭代,而 Print 输出所有迭代 - Python

  2. 2

    Foreach循环在第一次迭代中绑定所有数据

  3. 3

    Foreach循环在第一次迭代中绑定所有数据

  4. 4

    如果在第一次迭代和第二次迭代之间有一小段时间

  5. 5

    仅一次迭代,应用程序便崩溃了。没有可运行的设备,它根本无法运行。现在它在第一次迭代后崩溃

  6. 6

    为什么带有select的菜单第一次失败?

  7. 7

    Firebase调度功能在第一次调度后失败

  8. 8

    是否有一种干净的方法可以仅在第一次迭代时或在执行之前检查循环中的变量?

  9. 9

    为什么在使用 node 和 redis 时我的承诺没有解决?我的数组返回第一次迭代而不是等待整个代码运行

  10. 10

    广度第一次迭代?

  11. 11

    广度第一次迭代?

  12. 12

    遍历数组对象以检查值是否匹配仅适用于第一次迭代,后续迭代失败

  13. 13

    从表单添加和删除元素,第一次单击有效,后续单击不起作用

  14. 14

    在 dplyr 中使用 filter() 查找第一次出现的 grepl 值并返回它和所有后续行

  15. 15

    Pandas:如何在第一次满足条件后删除组的所有后续行?

  16. 16

    应用程序内购买第一次使用沙箱失败,下次工作正常

  17. 17

    Spring Cloud Hystrix在第一次命令调用时失败

  18. 18

    twitter小部件仅在第一次加载时有效,然后失败

  19. 19

    在一次迭代中显示带有Jtextarea的arraylist?

  20. 20

    PowerShell中的ForEach循环在第一次迭代后失败

  21. 21

    Spring Boot 作业调度程序

  22. 22

    第一次关闭所有子菜单

  23. 23

    第一次出现的变量有值吗?

  24. 24

    GridView第一次没有被点击

  25. 25

    Favicon第一次没有出现

  26. 26

    钩子第一次没有设置状态

  27. 27

    javascript没有看到第一次点击?

  28. 28

    GridView第一次没有被点击

  29. 29

    getElementById 仅在第一次有效

热门标签

归档