[阅读: 438] 2008-07-04 05:23:18
《Java与模式》一书中讲的单例模式中的双重锁定的例子
public class LazySingleton
{
private static LazySingleton m_instance = null;
private LazySingleton() { }
/**
* 静态工厂方法
*/
public static LazySingleton getInstance()
{
if (m_instance == null)
{
//More than one threads might be here!!!
synchronized(LazySingleton.class)
{
if (m_instance == null)
{
m_instance = new LazySingleton();
}
}
}
return m_instance;
}
}
作者提到了这种双重锁定并不正确,对于原因却解释的不是很清楚,哪位大虾能详细解释一下个中的原由?
机器人,
这首歌学会了没有?
我们的目标是->没有蛀牙!