Writing /volume1/Web/Public/dokuwiki/data/log/deprecated/2024-11-15.log failed
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン | |||
study:java:design_pattern:singleton [2010/03/10 13:13] – banana | study:java:design_pattern:singleton [2014/01/09 00:12] (現在) – banana | ||
---|---|---|---|
行 22: | 行 22: | ||
고전적인 싱글턴 구현법을 소개합니다. | 고전적인 싱글턴 구현법을 소개합니다. | ||
<code java> | <code java> | ||
- | public class Singleton{ | + | public class Singleton { |
| | ||
- | | + | |
- | | + | |
- | | + | if (uniqueInstance == null) { |
uniqueInstance = new Singleton(); | uniqueInstance = new Singleton(); | ||
} | } | ||
行 49: | 行 49: | ||
다음의 코드를 살펴보세요. | 다음의 코드를 살펴보세요. | ||
<code java> | <code java> | ||
- | public class Singleton{ | + | public class Singleton { |
| | ||
- | | + | |
- | | + | |
- | | + | if (uniqueInstance == null) { |
| | ||
} | } | ||
行 89: | 行 89: | ||
<code java> | <code java> | ||
- | public class Singleton{ | + | public class Singleton { |
| | ||
- | | + | |
- | | + | |
| | ||
} | } | ||
行 110: | 行 110: | ||
<code java> | <code java> | ||
- | public class Singleton{ | + | public class Singleton { |
private volatile static Singleton uniqueInstance; | private volatile static Singleton uniqueInstance; | ||
- | private Singleton(){} | + | private Singleton() {} |
- | public static Singleton getInstance(){ | + | public static Singleton getInstance() { |
- | if(uniqueInstance==null){ | + | if (uniqueInstance == null) { |
- | synchronized(Singleton.class){ | + | synchronized(Singleton.class) { |
- | if(uniqueInstance==null){ | + | if (uniqueInstance == null) { |
| | ||
} | } |