for (int i = 0; i < 3; i++) {
list.add("test" + i);
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
synchronized (list) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
list.add("test3");
}
}
});
thread.start();
synchronized (list) {
System.out.println(list);
}
What I'm not understanding right now is, the printout doesn't contain "test3". Shouldn't synchronizing list during the thread halt the println at the end?
So they should be in order of:
Thread.sleep();
list.add("test3");
println(list);
What's going on?