Skip to content

Commit 38bc588

Browse files
committed
Clarify that poolMap must use ConcurrentHashMap. No functional change.
Reported by Coverity scan running on Tomcat's internal copy of Commons Pool.
1 parent fe52b83 commit 38bc588

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,13 @@ public String toString() {
210210
* My hash of sub-pools (ObjectQueue). The list of keys <strong>must</strong> be kept
211211
* in step with {@link #poolKeyList} using {@link #keyLock} to ensure any
212212
* changes to the list of current keys is made in a thread-safe manner.
213+
*
214+
* Correct operation of the pool requires that a Map implementation is used that
215+
* supports concurrent read and write (e.g. ensureMinIdle() iterates over the key set
216+
* while other threads may be adding or removing keys) therefore explicitly define
217+
* this field as ConcurrentHashMap rather than Map.
213218
*/
214-
private final Map<K, ObjectDeque<T>> poolMap =
219+
private final ConcurrentHashMap<K, ObjectDeque<T>> poolMap =
215220
new ConcurrentHashMap<>(); // @GuardedBy("keyLock") for write access (and some read access)
216221

217222
/*

0 commit comments

Comments
 (0)