0

I am using spring batch remote partitioning. My first step prepares input files for all other steps. Other steps process input files.

To create input files on all 4 servers, my fist step should run on all servers. So I have set up consumer concurrency 1 on all servers and grid size 4 = number of servers.

But consumers on some servers consumes step execution request messages multiple times so on other servers the first step do not run and therefore input files do not get prepared which leads to failure of other steps which tries to process those file.

I want to run the first step if any step throw exception if resource (input file) is not available and then retry the same step which threw the exception.

How do I handle the exception thrown by FlatFileItemReader in strict mode if resource is not available and call the first step to prepare input files and retry same step which threw exception ?

More details are here

In documentation there are two types of exceptions mentioned

For this reason, Spring Batch provides a hierarchy of exceptions for handling parse exceptions: FlatFileParseException and FlatFileFormatException. FlatFileParseException is thrown by the FlatFileItemReader when any errors are encountered while trying to read a file. FlatFileFormatException is thrown by implementations of the LineTokenizer interface, and indicates a more specific error encountered while tokenizing.

Does it mean FlatFileParseException is thrown when there is an error while reading existing file or it is thrown when file do not exist at all ?

or in source code,

FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader where AbstractItemCountingItemStreamItemReader:read throws UnexpectedInputException ?

I am not sure how to use them ?

Community
  • 1
  • 1
vishal
  • 3,993
  • 14
  • 59
  • 102

1 Answers1

1

For this kind of problem use a JobExecutionDecider to redirect your job flow to step A if file doesn't exist of step B in other case.
This solution is more clear and show the real flow of your job without hide behind exception management (what about if SB mantainer decide to change FlatFileReader exception hierarchy, for example)?

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • Is there any possibility of adding retry limit to the JobExecututionDecide so that it should not execute go to infinite loop ? e.g. it should try 2-3 times and still it is unable to create file job should fail – vishal Jun 18 '14 at 10:41
  • Also, as I am using remote partitioning, how can I make sure decider runs on server where the file does not exist ? In that case, I think handling exception would be more suitable to my use case. This is my use case (problem) http://stackoverflow.com/questions/24237074/how-to-execute-some-partition-step-on-all-servers-only-once-using-spring-batch-p – vishal Jun 18 '14 at 11:14
  • Retry to decider can be added programmatically or using AOP; in decide() method call a service method and apply retry logic to it – Luca Basso Ricci Jun 18 '14 at 12:14
  • @second comment: IDK but, into decider, i think you can check remote file using a dedicated service method – Luca Basso Ricci Jun 18 '14 at 12:22