5
在多线程环境中,线程如何可能看到“部分构造的对象”?我知道它不是线程安全的,因为多个线程可以创建多个实例。非线程安全Singleton中的部分构造对象
class LazyInit
{ private static Resource resource = null;
public static getInstance()
{ if (resource == null) { resource = new Resource(); }
return instance;
}
}
查看https://secure.wikimedia.org/wikipedia/en/wiki/Double-checked_locking – Bozho 2010-10-19 08:38:28