The Artima Developer Community
Sponsored Link

Java Buzz Forum
Holliday Java Quiz: ConcurrentModificationException

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Holliday Java Quiz: ConcurrentModificationException Posted: Nov 26, 2008 10:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Holliday Java Quiz: ConcurrentModificationException
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

Tomorrow is Thanksgiving in the US. And here is a little Java quiz that you may want to ponder on while the turkey is in the oven. (BTW, I just recently realized I've been pronouncing the word 'oven' wrong all these years. Apparently it's not [oh-vn], but [uh-vn].)

Q: For the following Foo.java, is it ever possible for line 22 to throw a java.util.ConcurrentModificationException?

1    import java.util.ArrayList; 
2    import java.util.List; 
3     
4    public class Foo { 
5      private final List<Bar> bars = new ArrayList<Bar>(); 
6     
7      public void add(Bar bar) { 
8        synchronized(bars) { 
9          bars.add(bar); 
10       } 
11     } 
12    
13     public void remove(Bar bar) { 
14       synchronized(bars) { 
15         bars.remove(bar); 
16       } 
17     } 
18    
19     public void close() { 
20       synchronized(bars) { 
21         for (Bar bar: bars) { 
22           bar.close(); 
23         } 
24         bars.clear(); 
25       } 
26     } 
27   }

Have a happy Thanksgiving.

Read: Holliday Java Quiz: ConcurrentModificationException

Topic: 5-Line-Replacement of Apache Ant Previous Topic   Next Topic Topic: I Feel Speed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use