IMO, if the job stops abruptly at line X and you want to start at line X+1, it will happen only if the chunk size is 1. Because when chunk size is 1, every processed entry is committed and the JobContext knows exactly when it failed and where to restart from.
When your chunk size is greater than 1, let's say 8 and your job abruptly stops when the item 4 was being processed, then the first 3 items processed in the chunk is also not committed to the job execution tables at time of failure and the context would start from the same chunk from the 1st entry. In this case you will process the first 3 items again!
This can be avoided if you enable graceful shutdown of Spring Batch job when a kernel interruption happens so that the chunk is completely processed before the process ends. This will minimize the number of incidents reported but there would still be chances like - when you server's power plug is pulled of and the program doesn't get a chance to do a graceful shutdown.
Suggestions:
- If the process is idempotent, no trouble if some items are re-processed
- If the process is not idempotent, probably some kind of de-duplication check can be placed in a CompositeProcessor.
For graceful shutdown of the job, I have written some PoC code. You can see it here - https://github.com/innovationchef/batchpay/blob/master/src/main/java/com/innovationchef/batchcommons/JobManager.java