SleepyEgg

Tech News, Deals, & Games

  • Increase font size
  • Default font size
  • Decrease font size
Home News Tech News Using Java Iterator

Using Java Iterator

E-mail Print PDF
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()); } Share Link:
Bookmark Google Yahoo MyWeb Del.icio.us Digg Facebook Myspace Reddit Ma.gnolia Technorati Stumble Upon
Comments (0)Add Comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security code
Write the displayed characters


busy
 

Polls

Which is your favorite Game Console?
 

Login

               No account yet?