admin管理员组

文章数量:1241106

I'm describing the current behavior below,

  • Total records = 10
  • Total records picked by a Thread (or Chunk Size) = 5
  • Total Threads = 2

SkipPolicy is configured to skip 2 records at Job level.

Let's say Thread-1 processed it's Chunks successfully.

Below described is execution of Thread-2,

  • 1st, 2nd records processed successfully.
  • 3rd record processing failed (coz it's an invalid record & throw an Exception), Thread-2 chunk fails.

Now, record 1,2 are rollbacked. Then record 1,2 are picked, re-processed by another Thread and records 4,5 are also picked by another Thread and processed successfully.

I want to avoid this complete failure of Chunk when few records are invalid and skip them up to limit (i.e. 2 records at Job level).

Is their a way to achieve it using Spring Batch capabilities?

Note: I was thinking of custom approach wherein I won't be using SkipPolicy, instead I will have a counter for invalid record (and not throwing an Exception, just increment the counter) at JobExecution level. This approach will work by not failing the Chunk, instead skipping invalid records at Job level up to a limit. But it will make the Spring Batch tables data inconsistent (i.e. all invalid records will be considered good ones). Any views on this approach too?

本文标签: