简体   繁体   English

Spring Batch,块大小和跳过监听器

[英]Spring Batch, Chunk Size and Skip Listener together

I have a spring batch application, which is working good. 我有一个春季批处理应用程序,运行良好。 It just reads from text file and write to to oracle table. 它只是从文本文件读取并写入oracle表。 It performs the loading in chuck. 它在卡盘中执行加载。 Currently I have configured with chuck size of 2000. The issue is, when I implement the skip listener for this job, spring ignoring the chunk size i have given and it is inserting just one record at a time into database. 当前,我已经配置了2000的卡盘大小。问题是,当我为该作业实现跳过侦听器时,春天会忽略我给定的块大小,并且一次只向数据库中插入一条记录。 Skip listerner is just writing the invalid record to text file. 跳过侦听器只是将无效记录写入文本文件。 Is this how spring batch works ? 这是春季批处理的方式吗?

In a chunk, the ItemWriter will always first attempt to write the entire list of items in the chunk. 在一个块中, ItemWriter将始终首先尝试将整个项目列表写入块中。 However, if a skippable exception is thrown, the framework needs to figure out which item(s) caused the error. 但是,如果引发了可跳过的异常,则框架需要找出导致错误的项目。

To do this, the transaction is rolled back and then the items are retried one-by-one. 为此,将事务回滚,然后逐项重试项目。 This allows any item(s) that may have caused the issue to be passed to your skip listener. 这允许将可能导致问题的任何项目传递到您的跳过侦听器。 Unfortunately, it also removes the batch-iness of the chunk. 不幸的是,它也消除了块的批处理性。

In general, it is preferable (and will perform better) to do upfront validation in the processor, so you can "filter" the items out rather than throwing an exception and retrying the items individually. 通常,最好在处理器中进行前期验证(并且会更好地执行),因此您可以“过滤”出这些项目,而不是抛出异常并单独重试这些项目。

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

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