bg left bg right
      
  |  | 
Welcome to SleepyEgg Tech News and Coupon Deals!
Using Java Iterator PDF Print E-mail
(0 votes)
Written by Sleepy Egg   
Sunday, 31 July 2005
When using Java Iterator with a Java collection component in thread-safe way, we have to synchronize that component, not the iterator itslef. example: Map m = Collections.synchronizedMap(new HashMap()); ... Set s = m.keySet(); // Needn't be in synchronized block ... synchronized(m) { // Synchronizing on m, not s! Iterator i = s.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); }


Comments (0)add comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security image
Write the displayed characters


busy
 


Valid XHTML 1.0 Transitional