Return-Path: X-Original-To: apmail-activemq-dev-archive@www.apache.org Delivered-To: apmail-activemq-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 562E791F4 for ; Wed, 15 Feb 2012 21:05:27 +0000 (UTC) Received: (qmail 88236 invoked by uid 500); 15 Feb 2012 21:05:27 -0000 Delivered-To: apmail-activemq-dev-archive@activemq.apache.org Received: (qmail 88190 invoked by uid 500); 15 Feb 2012 21:05:27 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 88177 invoked by uid 99); 15 Feb 2012 21:05:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 21:05:27 +0000 X-ASF-Spam-Status: No, hits=-1998.7 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD,URI_HEX X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 21:05:21 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 1212B1B95B7 for ; Wed, 15 Feb 2012 21:05:00 +0000 (UTC) Date: Wed, 15 Feb 2012 21:05:00 +0000 (UTC) From: "Martin Serrano (Created) (JIRA)" To: dev@activemq.apache.org Message-ID: <1311388193.42565.1329339900075.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (AMQ-3720) ActiveMqMessageConsumer should have a blocking message wait that does not require Session synchronization MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org ActiveMqMessageConsumer should have a blocking message wait that does not require Session synchronization --------------------------------------------------------------------------------------------------------- Key: AMQ-3720 URL: https://issues.apache.org/jira/browse/AMQ-3720 Project: ActiveMQ Issue Type: Improvement Components: JMS client Reporter: Martin Serrano Fix For: 5.6.0 According to the documentation I've read and response to message [posts|http://activemq.2283324.n4.nabble.com/are-session-commit-and-consumer-receive-allowed-simultaneously-in-separate-threads-tt4387875.html], I've concluded that a call to consumer.receive(long) must guard against another thread using the session the consumer was created with. This makes it difficult to write performant code because a busy-wait idiom must be used in order to not hold a lock on session access while waiting for new messages. I've implemented a new method that will block until messages are available but does not require a session lock (it does not return any messages): {code:java} /** * Waits until messages are available. Unless the caller is interrupted, there will be a message available when this * method returns. */ public void waitUntilMessagesAvailable() { while (unconsumedMessages.isEmpty()) { synchronized (unconsumedMessages.getMutex()) { try { unconsumedMessages.getMutex().wait(2000); // the dispatch channel notifies when a message arrives } catch (InterruptedException e) { break; } } } } {code} I'll be happy to submit as a patch with associated unit test if there is consensus that this is needed and useful. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira