I'm using JdbcCursorItemReader for reading business objects and MyBatis with custom optimistic locking on version for updating (the objects can be modified by other APP). The idea is to retry update operation when it fail due to concurrent access exception.
The solution I was thinking of looks like this:
where lockListener would refresh data from DB with for the failed chunk:Code:<step id="update" > <tasklet> <chunk reader="reader" processor="processor" writer="writer" retry-limit="5"> <retryable-exception-classes> <include class="OptimisticLockingFailureException" /> </retryable-exception-classes> <listeners> <listener ref="lockListener"/> </listeners> </chunk> </tasklet> </step>
Is there any better solution to this problem?Code:public class OptimisticLockWriteListener implements ItemWriteListener<Item> { @Autowired private ItemDao dao; @Override public void onWriteError(Exception exception, List<? extends Item> items) { if (exception instanceof OptimisticLockingFailureException) { for (Item item : items) { Item newItem = dao.getItem(item.getId()); items.remove(item); items.add(newItem); } } } }


Reply With Quote
