Search code examples
javaspringsynchronizationjmsjmstemplate

Problem while using springs TransactionSynchronizationManager


I am using spring TransactionSynchronizationManager.Using this manager I register a new Synchronization TransactionSynchronizationAdapter and I override the afterCompletion(int status) method of this TransactionSynchronizationAdapter . Inside this afterCompletion the value of status must be coming as commited(0) but it is coming as active(0)

Here is the piece of code ::

TransactionSynchronizationManager
    .registerSynchronization(new TransactionSynchronizationAdapter() {
      public void beforeCompletion(){
        int status =Status.STATUS_COMMITTED;
        System.out.println("inside before completion block hurray");
      }
      public void afterCompletion(int status) {
        System.out.println("the value of status is " + status);
        System.out.println("coming after completion");
        if (status == Status.STATUS_COMMITTED) {
          final String memcachedKey = getMemcachedKey(pOrderId);
          System.out.println("the value of memcached key is inside the aftercompletion  " + memcachedKey);
          mCmatesMemCachedClient.set(memcachedKey, PROVISIONING_PASS);
          if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Tx commited. Set into memcached:Key="
                + memcachedKey + ",Value=" + PROVISIONING_PASS);
          }
        }
      }
    });
       }

Solution

  • Don't use Status.STATUS_COMMITTED, it has nothing to do with Spring. Use TransactionSynchronization.STATUS_COMMITTED instead.