Skip to content

Instantly share code, notes, and snippets.

@soh335
Created October 18, 2011 15:36
Show Gist options
  • Save soh335/1295733 to your computer and use it in GitHub Desktop.
Save soh335/1295733 to your computer and use it in GitHub Desktop.
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