4 ms·
Agreed. It's hard to discern the real value of using synchronized methods vs synchronized blocks when you end up reading: "Creating the synchronized block yield
by motxilo 16y ago
Agreed. It's hard to discern the real value of using synchronized methods vs synchronized blocks when you end up reading: "Creating the synchronized block yielded 16 lines of bytecode, whereas synchronizing the method returned just 5". As you point out, synchronization on a lock object is, as a rule of thumb, a much better option than synchronizing on the intrinsic lock, and thus losing control over it.
The explanation of volatile is woeful, to say the least. He doesn't even mention the main issue that volatile addresses (the only one?): visibility. Anyone really interested in this should read the following article by the author of JCIP: http://www.ibm.com/developerworks/java/library/j-jtp06197.html http://www.ibm.com/developerworks/java/library/j-jtp06197.ht...
I liked the section regarding ThreadLocal though (an example would've helped a bit).