That seems contradictory because once you exit the synchronized block everything should be visible.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Suma Rangaraj wrote:1) so what is the real issue with double checked locking on single vs multi-processor CPUs? How is the new memory model different?
2) if a thread 1 is executing a synchronized block and Thread 2 preempts thread 1, does it mean thread 1 will have to forcibly exit the synchronized block in between?
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
No. Once a thread is inside a synchronized block, it will not release the lock unless it calls the wait() method on the object it is synchronized on.
Pat Farrell wrote:And of course, all this is really about the Singleton Pattern, which is evil. See many other threads.
Stephan van Hulst wrote:Using a volatile variable would defeat the point of using double checked locking in the first place, wouldn't it? You're trading improved performance by avoiding a synchronization for decreased performance by using a volatile variable. So you end up with roughly the same performance, but less readability.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5