commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject [DBCP] Odd code in SharedPoolDataSource.getPooledConnectionAndInfo()
Date Thu, 14 Jan 2010 00:58:38 GMT
The method SharedPoolDataSource.getPooledConnectionAndInfo has the
following code:

            synchronized (userKeys) {
                if (userKeys.containsKey(username)) {
                    userKeys.remove(username);
                }
            }

Why not just use userKeys.remove(username)?
What is the purpose of checking the map first?
Also, the keys used for userKeys consist of the username+password, so
this doesn't really make sense anyway - it will only remove an entry
if the password is the empty string.

Note that the synch. block may still be needed, because
LRUMap.remove() - i.e. SequencedHashMap.remove() - updates the
underlying map and some other fields but is not synchronised.
Unfortunately the Javadoc does not say what the class invariants are.

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


Mime
View raw message