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

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

commit 2cfebb0429311e5f84c07a7d92c1ad50cb9c13ae
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Jan 23 09:35:49 2022 +0100

    CAMEL-17536 Fixed: ServicePool.doStop hangs during shutdown
---
 .../main/java/org/apache/camel/support/cache/ServicePool.java  | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java
index 4ac811b..fe0b6fe 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java
@@ -111,7 +111,13 @@ abstract class ServicePool<S extends Service> extends 
ServiceSupport implements
         }
         S s = getOrCreatePool(endpoint).acquire();
         if (s != null && cache != null) {
-            synchronized (cacheLock) {
+            if (isStoppingOrStopped()) {
+                // during stopping then access to the cache is synchronized
+                synchronized (cacheLock) {
+                    cache.putIfAbsent(s, s);
+                }
+            } else {
+                // optimize for normal operation
                 cache.putIfAbsent(s, s);
             }
         }
@@ -132,7 +138,7 @@ abstract class ServicePool<S extends Service> extends 
ServiceSupport implements
     }
 
     private Pool<S> getOrCreatePool(Endpoint endpoint) {
-        // its a pool so we have a lot more hits, so use regular get, and then 
fallback to computeIfAbsent
+        // it is a pool, so we have a lot more hits, so use regular get, and 
then fallback to computeIfAbsent
         Pool<S> answer = pool.get(endpoint);
         if (answer == null) {
             boolean singleton = endpoint.isSingletonProducer();

Reply via email to