You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/07/15 16:07:57 UTC

(camel) branch main updated: CAMEL-24078: camel-jms - Make JmsPollingConsumer.receive(timeout) thread-safe

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new ae6ec8c5b6ca CAMEL-24078: camel-jms - Make JmsPollingConsumer.receive(timeout) thread-safe
ae6ec8c5b6ca is described below

commit ae6ec8c5b6ca8d61d78687e7c021777c878cae93
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jul 15 18:07:50 2026 +0200

    CAMEL-24078: camel-jms - Make JmsPollingConsumer.receive(timeout) thread-safe
    
    Synchronize on the shared JmsTemplate to make set-timeout + receive
    atomic. The polling consumer is cached via ConsumerCache and shared
    across concurrent pollEnrich / ConsumerTemplate callers, so without
    synchronization one thread's timeout could be silently overwritten
    by another before the receive call executes.
    
    Closes #24738
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 .../apache/camel/component/jms/JmsPollingConsumer.java    | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
index a2755c5b981e..2e6eac1ee0ae 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
@@ -55,13 +55,16 @@ public class JmsPollingConsumer extends PollingConsumerSupport {
 
     @Override
     public Exchange receive(long timeout) {
-        setReceiveTimeout(timeout);
         Message message;
-        // using the selector
-        if (ObjectHelper.isNotEmpty(jmsEndpoint.getSelector())) {
-            message = template.receiveSelected(jmsEndpoint.getSelector());
-        } else {
-            message = template.receive();
+        // synchronize to make set-timeout + receive atomic, as the polling consumer
+        // may be shared across concurrent pollEnrich / ConsumerTemplate callers
+        synchronized (template) {
+            setReceiveTimeout(timeout);
+            if (ObjectHelper.isNotEmpty(jmsEndpoint.getSelector())) {
+                message = template.receiveSelected(jmsEndpoint.getSelector());
+            } else {
+                message = template.receive();
+            }
         }
         if (message != null) {
             return getEndpoint().createExchange(message, null);