中国开发网: 论坛: 程序员情感CBD: 贴子 651684
haitao
java的synchronized(classx) { code; }不是让整个code不受打断的执行?
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;
}

相关信息:


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