This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 88dd89f488 Improved: Replace ConcurrentLinkedHashMap by Caffeine (OFBIZ-6747) 88dd89f488 is described below commit 88dd89f4889e4c70db9ed7669a019fc378428a72 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Oct 18 12:16:44 2022 +0200 Improved: Replace ConcurrentLinkedHashMap by Caffeine (OFBIZ-6747) Here only ServiceDispatcher is modified. Thanks: Ben Manes for suggestion and help --- .../java/org/apache/ofbiz/service/ServiceDispatcher.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java index dd85ece5fd..39dc2369f2 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java @@ -58,11 +58,13 @@ import org.apache.ofbiz.service.job.JobManager; import org.apache.ofbiz.service.job.JobManagerException; import org.apache.ofbiz.service.semaphore.ServiceSemaphore; -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + + /** - * The global service dispatcher. This is the "engine" part of the - * Service Engine. + * The global service dispatcher. This is the "engine" part of the Service Engine. */ public final class ServiceDispatcher { @@ -70,8 +72,10 @@ public final class ServiceDispatcher { public static final int LRU_LOG_SIZE = 200; public static final int LOCK_RETRIES = 3; - private static final Map<RunningService, ServiceDispatcher> RUN_LOG = new ConcurrentLinkedHashMap.Builder<RunningService, - ServiceDispatcher>().maximumWeightedCapacity(LRU_LOG_SIZE).build(); + private static final Cache<RunningService, ServiceDispatcher> RUN_LOG = Caffeine.newBuilder() + .maximumSize(LRU_LOG_SIZE) + .build(); + private static ConcurrentHashMap<String, ServiceDispatcher> dispatchers = new ConcurrentHashMap<>(); // FIXME: These fields are not thread-safe. They are modified by EntityDataLoadContainer. // We need a better design - like have this class query EntityDataLoadContainer if data is being loaded. @@ -1107,7 +1111,7 @@ public final class ServiceDispatcher { } public static Map<RunningService, ServiceDispatcher> getServiceLogMap() { - return RUN_LOG; + return RUN_LOG.asMap(); } }