void registerCleanUpListener ( TransactionSynchronizationRegistry transactionSynchronizationRegistry , JMSContext contextInstance ) { //to avoid registration of more listeners for one context, flag in transaction is used. Object alreadyRegistered = transactionSynchronizationRegistry . getResource ( contextInstance ) ; if ( alreadyRegistered == null ) { transactionSynchronizationRegistry . registerInterposedSynchronization ( new AfterCompletionSynchronization ( contextInstance ) ) ; transactionSynchronizationRegistry . putResource ( contextInstance , AfterCompletionSynchronization . class . getName ( ) ) ; } }
Closing of transaction scoped JMSContext is executed through Synchronization listener . This method registers listener which takes care of closing JMSContext .