The Javamex companion blog. This blog includes both technical articles relating to the programming information that you'll find on the Javamex site, plus information covering the IT industry more generally.
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:
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 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.
2 comments:
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!
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.
Post a Comment