[英]Is this Singleton a thread safe one ? I can't see how?
考虑单例:
public final class MySingleton {
private static class Nested
{
private static final MySingleton INSTANCE = new MySingleton();
}
private MySingleton()
{
if (Nested.INSTANCE != null)
{
throw new IllegalStateException("Already instantiated");
}
}
public static MySingleton getInstance()
{
return Nested.INSTANCE;
}
}
我没有锁,但是为什么这是解决Singleton问题的线程安全解决方案?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.