You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2025/08/30 11:01:09 UTC

(tomcat) branch main updated: Clarify that poolMap must use ConcurrentHashMap. No functional change.

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 68a7046763 Clarify that poolMap must use ConcurrentHashMap. No functional change.
68a7046763 is described below

commit 68a7046763ac3e26692569adeef01a4a65df2ce8
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Sat Aug 30 12:01:03 2025 +0100

    Clarify that poolMap must use ConcurrentHashMap. No functional change.
    
    Reported by Coverity scan running on Tomcat's internal copy of Commons
    Pool.
---
 java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
index 07e89b6690..69493b77b2 100644
--- a/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
+++ b/java/org/apache/tomcat/dbcp/pool2/impl/GenericKeyedObjectPool.java
@@ -209,8 +209,13 @@ public class GenericKeyedObjectPool<K, T> extends BaseGenericObjectPool<T>
      * My hash of sub-pools (ObjectQueue). The list of keys <strong>must</strong> be kept
      * in step with {@link #poolKeyList} using {@link #keyLock} to ensure any
      * changes to the list of current keys is made in a thread-safe manner.
+     *
+     * Correct operation of the pool requires that a Map implementation is used that
+     * supports concurrent read and write (e.g. ensureMinIdle() iterates over the key set
+     * while other threads may be adding or removing keys) therefore explicitly define
+     * this field as ConcurrentHashMap rather than Map.
      */
-    private final Map<K, ObjectDeque<T>> poolMap =
+    private final ConcurrentHashMap<K, ObjectDeque<T>> poolMap =
             new ConcurrentHashMap<>(); // @GuardedBy("keyLock") for write access (and some read access)
 
     /*


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org