简体   繁体   English

Spring Batch Transaction 使用基于块的处理

[英]Spring Batch Transaction using Chunk based processing

enter image description hereI am using chunk based processing using Spring Batch to read data in chunks from DB using JdbcPagingItemReader.在此处输入图像描述我正在使用 Spring Batch 使用基于块的处理来使用 JdbcPagingItemReader 从 DB 中读取块中的数据。 Now , I am killing the task in between the write stage of a chunk.现在,我正在杀死一个块的写入阶段之间的任务。 Ideally the previous records in the chunk should have got rolled back but that did not happen.理想情况下,块中的先前记录应该已经回滚,但没有发生。 The DB used here is DB2 .这里使用的数据库是 DB2 。

The approach which I used was- to set Autocommit false for the connection and then after the write steps were complete I used the commit statement.This approach worked fine for a small set of data.我使用的方法是为连接设置 Autocommit false,然后在写入步骤完成后,我使用了 commit 语句。这种方法适用于一小部分数据。 But in real time there would be millions of records.但实时会有数百万条记录。

So , is this the right approach and if not then what can be the other solutions.那么,这是正确的方法吗?如果不是,那么其他解决方案是什么。

Thanks!谢谢!

If I'm understanding you correctly: do you want to do thousands of processings without committing.如果我对您的理解正确:您是否想在不提交的情况下进行数千次处理。 And when everything is done committing?当一切都完成提交? Don't do so.不要这样做。 You will have serious problems, both in the system and in the data base.您将在系统和数据库中遇到严重的问题。 Things like that you better use another strategy, for example: A temporary table.像这样的事情你最好使用另一种策略,例如:一个临时表。 It goes on committing and when it finishes, it analyzes the result and if everything is right, it executes an update from the temporary to the final table.它继续提交,完成后,它分析结果,如果一切正常,它执行从临时表到最终表的更新。

You have to divide and conquer:你必须分而治之:

  1. Run the process that generates the thousands of rows in a temporary table.运行在临时表中生成数千行的进程。
  2. Analyze the result, it can be an analysis that results in the deletion of unsatisfactory lines or even an analysis that excludes the entire process.分析结果,可以是导致不满意行删除的分析,甚至可以是排除整个过程的分析。
  3. Perform what should be done based on the analysis process.根据分析过程执行应该做的事情。

I would create three or more Spring Batch Steps for each step of the one described above.我将为上述步骤的每个步骤创建三个或更多 Spring Batch Steps。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM