Announcement Announcement Module
No announcement yet.
Optimistic locking - retry Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Optimistic locking - retry

    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:

           <step id="update" >
                    <chunk reader="reader" processor="processor" writer="writer" retry-limit="5">
                            <include class="OptimisticLockingFailureException" />
                            <listener ref="lockListener"/>
    where lockListener would refresh data from DB with for the failed chunk:

    public class OptimisticLockWriteListener implements ItemWriteListener<Item> {
        private ItemDao dao;
        public void onWriteError(Exception exception, List<? extends Item> items) {
            if (exception instanceof OptimisticLockingFailureException) {
                for (Item item : items) {
                    Item newItem = dao.getItem(item.getId());
    Is there any better solution to this problem?

  • #2
    Just defining <retryable-exception-classes> should work. Also specify fully qualified name of the exception to be retried.
    In my opinion, you don't need the OptimisticLockWriteListener for exception retry. You can use the listener to log to file, etc. in case of an exception. Although I am not very sure if the listener will be called in case of a retryable exception.


    • #3
      The problem is that I need not only retry but also re-read items that failed. OptimisticLockWriteListener is called but collection is unmodifiable, so the solution does not work anyway. I think I've found a solution here:

      but I think I would need to "tweak" my job definition somehow to make it working.
      Last edited by howieB; Aug 22nd, 2011, 09:05 AM.