`

关于volatile变量

    博客分类:
  • java
阅读更多

今天看到了一个单例模式代码:

public class Singleton
{
	private volatile static Singleton uniqueInstance;

	private Singleton()
	{
	}

	public static Singleton getInstance()
	{
		if (uniqueInstance == null)
		{
			synchronized (Singleton.class)
			{
				if (uniqueInstance == null)
				{
					uniqueInstance = new Singleton();
				}
			}
		}
		return uniqueInstance;
	}
}

 看到了一个关键字:volatile,由于自己不理解,上网查了一下。

http://www.ibm.com/developerworks/cn/java/j-jtp06197.html

http://blog.21ic.com/user1/2949/archives/2007/35599.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics