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
commit 2bfa25566b361d489d4048cc61d610437ee6606d 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();
