- Simplicity by design

Double-Checked Locking


Double Checked Locking (DCL) is commonly used pattern / anti-pattern for creating singleton objects in a multi threaded applications. This is denoted as anti-pattern because the implementation is broken and in versions before Java 1.5. As of JDK5, there is a new Java Memory Model and Thread specification. With respect to .NET its controversial. People suggest to avoid DCL in .NET. But the .net framework itself relies on DCL when instantiating providers.

If you use Reflector and navigate to the Membership / Roles class Initialize method you could see them using the DCL.

So, care must be taken while using the Double-checked locking pattern to ensure safety of your code

Share
  • Turn this article into a PDF!
blog comments powered by Disqus