Fork me on GitHub

多线程下单例模式的优化

class Single
{
	private static Single s = null;

	private Single()
	{
	}

	private static Single getInstance()
	{
			if(s == null) 
			{
				synchronized(Single.class)
				{
					if(s == null)
					{
						s = new Single();
					}
				}
			}
			return s;
	}
}

  

posted @ 2015-02-09 11:16  龙族小龙  阅读(256)  评论(0编辑  收藏  举报