Originally posted by Satya Maheshwari:
If this is not an atomic operation, it can result in 'true' if multiple threads change the value of 'n'
It's indeed not an atomic operation, but the class has no setters, so the value can't be changed. The secret to the problem here is in
unsafe publication of the object, and to understand that one has to understand the so-called
memory model of Java.
I have read that book, and wholeheartedly recommend it to every Java developer. There's much to know about concurrency in Java -a topic that gets more important by the year, what with multithreaded processors and multicore processors-, and this book teaches it all, including all the stuff that got introduced in Java 5.
[ August 15, 2008: Message edited by: Ulf Dittmer ]