Cezar's reflections

Saturday, August 08, 2009

The double checked locking - Broken

If you're thinking of using the following code to optimize thread contention in java, don't!


class Foo
{
private Helper helper = null;

public Helper getHelper()
{
if (helper == null)
{
synchronized(this)
{
if (helper == null)
{
helper = new Helper();
}
}
}

return helper;
}
}
Read the following posts first:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home