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

mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release24.09 by this push:
     new 12b4c8e8cc Start the JMS listener factory thread only for the 
published instance
12b4c8e8cc is described below

commit 12b4c8e8ccdf136f0f0587104421b33404a83e38
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 30 19:58:14 2026 +0530

    Start the JMS listener factory thread only for the published instance
    
    JmsListenerFactory.getInstance created a factory whose constructor already 
started the listener loader thread, and only then tried to publish it with 
compareAndSet. When two dispatchers were created at the same time, the instance 
that lost the race was discarded but its thread kept loading listeners into the 
same static maps, under a different lock, so the same JMS listener could be 
created and connected twice and the extra one was never closed. getInstance now 
builds the factory with [...]
---
 .../apache/ofbiz/service/jms/JmsListenerFactory.java   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git 
a/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java
 
b/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java
index a8825ab933..ef102255bc 100644
--- 
a/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java
+++ 
b/framework/service/src/main/java/org/apache/ofbiz/service/jms/JmsListenerFactory.java
@@ -61,8 +61,12 @@ public class JmsListenerFactory implements Runnable {
     public static JmsListenerFactory getInstance(Delegator delegator) {
         JmsListenerFactory instance = JL_FACTORY_REF.get();
         if (instance == null) {
-            instance = new JmsListenerFactory(delegator);
-            if (!JL_FACTORY_REF.compareAndSet(null, instance)) {
+            JmsListenerFactory created = new JmsListenerFactory(delegator, 
false);
+            if (JL_FACTORY_REF.compareAndSet(null, created)) {
+                // only the published instance runs the loader thread
+                created.start();
+                instance = created;
+            } else {
                 instance = JL_FACTORY_REF.get();
             }
         }
@@ -70,7 +74,17 @@ public class JmsListenerFactory implements Runnable {
     }
 
     public JmsListenerFactory(Delegator delegator) {
+        this(delegator, true);
+    }
+
+    private JmsListenerFactory(Delegator delegator, boolean start) {
         this.delegator = delegator;
+        if (start) {
+            start();
+        }
+    }
+
+    private void start() {
         thread = new Thread(this, this.toString());
         thread.setDaemon(false);
         thread.start();

Reply via email to