Another question from a viewer. We have this code: class C { private int x; public C(int v) { this.x = v; } public synchronized int get() { return this.x; } public synchronized void set(int v) { this.x = v; } } (For the actual question as it was worded, the short answer is, "yes") The question was one I get a lot. He asked how one thread can safely read the initial write of v to x. That is to say, if we have: Thread 1: globalRef = new C(5); Thread 2: C ref = globalRef; if (ref != null) { int r1 = ref.x; } How can we change this code to guarantee that the read in Thread 2 will see the value 5 for x (assuming that ref is not null)? Let's back up for a minute, and talk about why, in the code as written, the read in Thread 2 will not see the value 5 for x . Under the Java memory model, for one thread to be guaranteed to see an update made to a variable by another thread, there must be a happens-before relationship between the update and th
Jeremy Manson's blog, which goes into great detail either about concurrency in Java, or anything else that the author happens to feel is interesting or relevant to the target audience.