1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package com.wetuo.javabase;
public class SingletonDemo {
private static SingletonDemo instance = new SingletonDemo();
private SingletonDemo() {}
public static SingletonDemo getInstance() {
return instance;
} //充血模式
} 方法二 public class SingletonDemo {
private static SingletonDemo instance = null ;
private SingletonDemo() {}
public static synchronized SingletonDemo getInstance() { //保证只new一次
if ( null ==instance)
return new SingletonDemo();
else
return instance;
} //饥饿模式
}
|
本文转自arac 51CTO博客,原文链接:http://blog.51cto.com/skyarac/1351015,如需转载请自行联系原作者