中国开发网: 论坛: 程序员情感CBD: 贴子 651604
龙之吻
[技术贴]请教海豹牛等众抓蛙牛人.
《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;
}
}

作者提到了这种双重锁定并不正确,对于原因却解释的不是很清楚,哪位大虾能详细解释一下个中的原由?


机器人,这首歌学会了没有?

我们的目标是->没有蛀牙!

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录