Příklad 3 (viz Wiki)
public class SomeThreadSafeClass {
private List<String> data = Collections.synchronizedList(new ArrayList<String>());
public void addData(String newObject) {
data.add(newObject);
}
public synchronized void dumpData() {
for(String s : data) {
System.out.println(s);
}
}
}