haitao ·
·
阅读: 566
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;
}