How about the following instead? As Tim pointed out, the consumer close won't return until no more calls to onMessage are guaranteed. I believe that also means it won't return while onMessage() is actively being called.
@Tim - can you confirm? If that's correct, the following should do the job effectively: ON MESSAGE LOCK semaphore IF shutdown started THEN ABORT END IF SET processing active UNLOCK semaphore DO process message LOCK semaphore SET processing NOT active UNLOCK semaphore ON LISTENER SHUTDOWN LOCK semaphore SET shutdown started UNLOCK semaphore DO close consumer SET not done WHILE not done LOCK semaphore IF processing NOT active THEN SET done END IF UNLOCK semaphore IF NOT done THEN DELAY // short sleep; note there are methods to eliminate the sleep and use a notification; I don't recall them for C++ right now END IF END WHILE DO delete message listener That last part about the delay can be solved with another semaphore as well. Also, if the part up to "ABORT" in the listener can be done safely even after the listener is deleted, then this works even if the consumer close can return while the call to onMessage() is still active. -- View this message in context: http://activemq.2283324.n4.nabble.com/how-to-safely-delete-a-cms-MessageListener-object-tp4689939p4690003.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.