单例java_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 单例java

单例java

 2013/12/17 13:09:05  fangzi370307  程序员俱乐部  我要评论(0)
  • 摘要:一、publicclassSingleton{privateSingleton(){};privatestaticSingletonsingle=newSingleton();publicstaticSingletongetInstance(){returnsingle;}}二、publicclassSingleton{privateSingleton(){};privatestaticSingletonsingle=null
  • 标签:Java
class="java">
一、
public class Singleton {

	private Singleton() {
	};

	private static Singleton single = new Singleton();
	public static Singleton getInstance() {
		return single;
	}
}


二、
public class Singleton {

	private Singleton() {
	};

	private static Singleton single = null;

	public synchronized static Singleton getInstance() {
		if (single == null) {
			single = new Singleton();
		}
		return single;
	}
}

发表评论
用户名: 匿名