Return-Path: X-Original-To: apmail-activemq-users-archive@www.apache.org Delivered-To: apmail-activemq-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 071E917232 for ; Thu, 15 Jan 2015 18:23:24 +0000 (UTC) Received: (qmail 30350 invoked by uid 500); 15 Jan 2015 18:23:25 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 30296 invoked by uid 500); 15 Jan 2015 18:23:25 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 30284 invoked by uid 99); 15 Jan 2015 18:23:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jan 2015 18:23:24 +0000 X-ASF-Spam-Status: No, hits=3.1 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX,URI_TRY_3LD X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of tbain98@gmail.com designates 209.85.216.41 as permitted sender) Received: from [209.85.216.41] (HELO mail-qa0-f41.google.com) (209.85.216.41) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jan 2015 18:23:20 +0000 Received: by mail-qa0-f41.google.com with SMTP id bm13so12305050qab.0 for ; Thu, 15 Jan 2015 10:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=XgKa5Iuboajl40fmdPtzeeyLCLBxSlmH1KVdvCVCFvE=; b=TplangpfCqVSPIdmDihmWGnsZb2wEfi3AwoE/wFsQ6BzavXWV1ohOyGcVsqq3TFqa6 7UUpIfgljQmE1tir+yR8GdQujmgq5jAQNdOtDYPaQl2NCVKpbpoF9W9y3fcc0ZEa+acO ofjlBO9m52vvxcfK/PLbOrmYqT+LRgerddfR/5BWiO6xI6pwsKFzO7sAn2PVKWQB0otT JkmlO/w+ZbJJSE+T6mbft8GzdHHQwddRmzSw0rcfNnxGdR6y78aqcXw5flRCzIoBOF8r k7l4Ov9XrwnGyqvHe/IcEZyJQBwtnu53O71AviE5xNtwan57NOQzmO+ThbMz6BHQ7x4M GJPQ== X-Received: by 10.224.131.70 with SMTP id w6mr18530082qas.78.1421346180350; Thu, 15 Jan 2015 10:23:00 -0800 (PST) MIME-Version: 1.0 Sender: tbain98@gmail.com Received: by 10.229.37.130 with HTTP; Thu, 15 Jan 2015 10:22:40 -0800 (PST) In-Reply-To: <1421340046000-4689955.post@n4.nabble.com> References: <1421283663687-4689939.post@n4.nabble.com> <1421339272906-4689951.post@n4.nabble.com> <1421340046000-4689955.post@n4.nabble.com> From: Tim Bain Date: Thu, 15 Jan 2015 11:22:40 -0700 X-Google-Sender-Auth: KJK7Ku9_OCpf21SU5DC3IKvpiys Message-ID: Subject: Re: how to safely delete a cms::MessageListener object To: ActiveMQ Users Content-Type: multipart/alternative; boundary=001a11c2a2902ee05d050cb4f2a0 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c2a2902ee05d050cb4f2a0 Content-Type: text/plain; charset=UTF-8 You could probably handle that problem in most cases by adding a flag that says whether onMessage() is currently running (increment on entry, decrement on exit) combined with a long enough sleep() call; it's a bit ham-fisted, but it should be good enough. Close the consumer (so you know that there is at most one more message), sleep for your amount of time, then check whether onMessage() is still running and sleep until it's not (and maybe a bit more for good measure to make sure that the code that calls onMessage() gets a chance to finish, too), then delete the listener object. The only risk there is if you don't sleep long enough initially and there's still a message waiting to have onMessage() called, but hopefully you can find a duration that reduces that risk to close to zero even if you can't entirely prevent the issue. A better solution would be to have a method (isSafeToDelete()?) on the listener that will return false until the listener has been closed and the last message has been processed and the thread has exited. That sounds like a useful enhancement you could request in JIRA... On Thu, Jan 15, 2015 at 9:40 AM, Steve Rice wrote: > Thanks for the suggestions. I have a request-and-reply mechanism, where > the > reply arrives asynchronously to a temporary queue, and a consumer has been > set up to listen for that reply sent to the temporary queue. At some > point, > after waiting awhile to receive the reply and still not getting it, the > main > thread may decide that it has given up on receiving the reply and wants to > cleanup the objects that were set up to receive the reply. It appears I > can > set the message listener associated with the consumer to NULL (or close the > consumer), which will prevent an incoming reply from calling the > onMessage() > function associated with message listener. That stops the listening. The > case I am concerned about is when the onMessage() function has begun > executing to process a reply, but has not yet reached a statement where I > can set a flag to indicate to the main thread that it is executing. At > that > moment, the main thread does not know that there is a concurrent execution > of onMessage() and may proceed with de-allocating objects used by > onMessage(). Perhaps this window of vulnerability can be closed by using > C++11 shared pointers, but that would require modifying the CMS code. > > Steve Rice > > > > -- > View this message in context: > http://activemq.2283324.n4.nabble.com/how-to-safely-delete-a-cms-MessageListener-object-tp4689939p4689955.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. > --001a11c2a2902ee05d050cb4f2a0--