简体   繁体   中英

XA transactions in Spring Batch

I'm writing a number of batch jobs with Spring Batch which mostly do export/import from/to database. The Spring Batch job repository database and target database(from/to which I'm read/write data) are located on different machines.

My question is should I use XA transactions in this configuration?

I wondering about the scenario when at some point of time link to the job repository db brakes, will it potentially corrupt the data? Like this:

  1. Job started (write to job repository)
  2. Read/process/write in target db within transaction
  3. Link to job repository db brakes and job fails

And finally I have updated target db but job is failed so same data will be processed again upon the job restart.

Spring Batch has the facility within it's reader/writers to disable the interim state saving (you set the property saveState to false). this allows you to manage the state of the processing independently of Spring Batch JobRepository.

in your example, you would maintain a 'processed flag' on the read table and modify the select statement to a select * from x where processed = false . this would make you less dependent on the state of the JobRepository.

have a look at http://static.springsource.org/spring-batch/reference/html/readersAndWriters.html#process-indicator that explains it in more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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