Skip to main content

Posts

Showing posts from October, 2010

Double Checked Locking And Java Singletons

I read this article by Bill Pugh on why the double checked locking idiom does not guarantee thread safety in Java Singletons. That article taught me a lot of new things, and to be honest, I had to re-read that article at least a couple of times to partially understand it :-) I recently created a presentation to make at DevCamp on this topic. What follows are my slides and an explanation of each slide. I hope you enjoy this presentation and find it useful. Double checkedlockingjavasingletons View more presentations from parag . slide 1: In this presentation I will discuss the double checked locking idiom, and explain why it does not work to provide thread safety to Java Singletons. I will also talk about how using volatile fields will fix the problem in JDK 1.5 onwards. slide 2 (Singleton): Many of you might already have used the Singleton design pattern . In case you have not, here is a brief description of what Singletons are. The Singleton pattern is used when we want to ensure