Tuesday, August 12, 2008

Improvements to section on 'volatile'

The site's section on the Java volatile keyword has been expanded to include information such as:


Anonymous said...

I believe that there is a small mistake with the double-checked locking example. Shouldn't the getInstance method not be synchronized on item (3) from the following page: http://www.javamex.com/tutorials/double_checked_locking_fixing.shtml

Otherwise the code loses the performance gains of using DCL plus it wouldn't need volatile at that point.

Thanks for all the work on the site!

Neil Coffey said...

Thanks for spotting this. The whole point of item (3) is indeed that the getInstance() method itself no longer needs to be declared synchronized. The example has been duly corrected.