Created
October 18, 2011 15:36
-
-
Save soh335/1295733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CopyOnWriteArrayList; | |
public class Hoge { | |
public static void main(String[] args) { | |
// final List<String> list = new ArrayList<String>(); | |
final List<String> list = new CopyOnWriteArrayList<String>(); | |
list.add("a"); | |
list.add("b"); | |
list.add("c"); | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
while (true) { | |
for (String s : list) { | |
System.out.println(s); | |
} | |
} | |
} | |
}).start(); | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
while(true) { | |
list.add("d"); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}).start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment