dev@grizzly.java.net

A question about outbound connection cache

From: Minoru Nitta <minoru.nitta_at_jp.fujitsu.com>
Date: Sun, 15 Feb 2009 11:28:37 +0900

Hi All,


 I have a question about outbound connection cahce implementation.

http://blogs.sun.com/oleksiys/entry/connection_management_cache_in_grizzly


I have tested it and it works fine in most cases. But sometimes it caused unexpected
results. I am trying to understand the source code regarding this feature, and I
foud out the point which may cause the problem.

In OutboundConnectionCacheBlockingImpl, there is a HashMap called entryMap
whose key is ContactInfo(actually it is a CacheableConnectorHandler).

According to the pseudo code on the above URL, I can get CacheableConnectorHandler
by calling Controller.acquireConnectorHandler and can release the handler by calling
Controller.releaseConnectorHandler. If CacheableConnectorHandler is put back
to CacheableConnectorHandler pool, it will bes reused, and IMHO, it may cause
unexpected results.

That is because if CacheableConnectorHandler is reused, targetAddress field is
rewritten, and it is a part of hashCode() (also used in equals() method). So, it is
possible that hash code of the key is changed after putting the value in
the entryMap.


Minoru