good point. I'll have to review the code in more detail. --- Dain Sundstrom <[EMAIL PROTECTED]> wrote: > Hiram, > > This type of construct creates some trick code. You > iterate over the > keys, and I assume somewhere in the code you do > clients.get(key). Well > there is no guarantee the the key is associated. I > bet there are a ton > of other issues as your iterator in the read phase > drifts from reality > of changing clients HashMap. Anyway, I hope you > documented this > heavily. > > -dain > > On Thursday, February 13, 2003, at 12:28 PM, Hiram > Chirino wrote: > > > Yep.. your way is valid too but you take a > > synchronization hit on every read. The otherway, > the > > performace hit is on the write. As I said > previously, > > if you read the map ALLOT more than you write to > it, > > then it makes sense to do it backwards. > > > > Regards, > > Hiram > > > > --- Dain Sundstrom <[EMAIL PROTECTED]> wrote: > >> This seems backwards to me. I usually do > something > >> like this: > >> > >> class X > >> { > >> HashMap clients = new HashMap(); > >> > >> public void someMethod() > >> { > >> synchronized(clients) > >> { > >> m.put(dc, cq); > >> } > >> ... > >> } > >> public void someOtherMethod() > >> { > >> HashMap clientsCopy = null; > >> synchronized(clients) > >> { > >> clientsCopy = new HashMap(clients); > >> } > >> Iterator i = > >> clientsCopy.keySet().iterator(); > >> while( i.hasNext() ) > >> { > >> ... > >> } > >> } > >> } > >> > >> For the insert, you only get a quick synchronized > >> around the add, and > >> on iteration you get a single copy in the > >> synchronize. If the > >> iteration very small and quick, I sometimes put > the > >> entire iteration in > >> the synchronized block, but you need to be > careful > >> about open calls. > >> > >> -dain > >> > >> On Thursday, February 13, 2003, at 11:20 AM, > Scott M > >> Stark 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 > >> > >> > >> > >> > > > ------------------------------------------------------- > >> 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 > > > > === message truncated ===
__________________________________________________ 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