Looks like you might be digging through some mq code
:)

I don't think that construct is too bogus...  It
provides a copy write hashmap.  Once the hashmap has
been updated, the rest of the read methods can treat
the hashmap as an imutable.  No one will update that
hashmap ever again.  To update it, you have to
generate another copy.

This is very good when you are reading the map 90% of
the time and updating it 10%.  I don't see why this is
not thread safe.

Regards,
Hiram

--- Scott M Stark <[EMAIL PROTECTED]> wrote:
> I have seen this usage construct in a few places in
> the code and it makes
> no sense to me:
> 
> class X
> {
>     HashMap clients = new HashMap();
> 
>     public void someMethod()
>     {
>        synchronized(clients)
>         {
>             HashMap m = new HashMap(clients);
>             m.put(dc, cq);
>             clients=m;
>        }
>         ...
>     }
>     public void someOtherMethod()
>     {
>         Iterator i = clients.keySet().iterator();
>         while( i.hasNext() )
>         {
>             ...
>         }
>     }
> }
> 
> The unsynchronized clients HashMap is synchronized
> and copied when
> modified and accessed without synchronization in
> other contexts. This is
> not thread safe for the accesses and makes for very
> expensive updates.
> Why isn't the HashMap simply synchronized and used
> without copying?
> 
> xxxxxxxxxxxxxxxxxxxxxxxx
> Scott Stark
> Chief Technology Officer
> JBoss Group, LLC
> xxxxxxxxxxxxxxxxxxxxxxxx
> 
> 
>
-------------------------------------------------------
> This SF.NET email is sponsored by: FREE  SSL Guide
> from Thawte
> are you planning your Web Server Security? Click
> here to get a FREE
> Thawte SSL guide and find the answers to all your 
> SSL security issues.
>
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
> _______________________________________________
> Jboss-development mailing list
> [EMAIL PROTECTED]
>
https://lists.sourceforge.net/lists/listinfo/jboss-development


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com


-------------------------------------------------------
This SF.NET email is sponsored by: FREE  SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your  SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to