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

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

commit f8f4ebcfa9da6665e2d0de77abcba3b3b92fc7cd
Author: Guillaume Nodet <gno...@gmail.com>
AuthorDate: Wed May 15 17:34:25 2024 +0200

    Fix wrong synchronization pattern
---
 .../apache/camel/support/component/AbstractApiEndpoint.java | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
index 0192468d239..5901086ce03 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
@@ -74,7 +74,7 @@ public abstract class AbstractApiEndpoint<E extends ApiName, 
T>
     private List<ApiMethod> candidates;
 
     // cached Executor service
-    private ExecutorService executorService;
+    private volatile ExecutorService executorService;
 
     // cached property names and values
     private Set<String> endpointPropertyNames;
@@ -337,13 +337,14 @@ public abstract class AbstractApiEndpoint<E extends 
ApiName, T>
     }
 
     public final ExecutorService getExecutorService() {
-        if (this.executorService == null) {
-            // synchronize on class to avoid creating duplicate class level 
executors
-            synchronized (getClass()) {
-                this.executorService = getExecutorService(getClass(), 
getCamelContext(), getThreadProfileName());
+        if (executorService == null) {
+            synchronized (this) {
+                if (executorService == null) {
+                    executorService = getExecutorService(getClass(), 
getCamelContext(), getThreadProfileName());
+                }
             }
         }
-        return this.executorService;
+        return executorService;
     }
 
     /**

Reply via email to