일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 보안
- Android
- Eclipse
- 코스피
- Linux
- ubuntu
- uml example
- Audacity
- UX
- eclipse35
- 주식
- IT 키워드
- LDAP
- conemu
- Algorithm
- KOSPI
- 작성중
- 기술사
- Qmail
- 태터수정
- 안드로이드
- adb
- 공매도
- 우분투
- 알고리즘
- java
- unix
- 도서
- IPTV
Archives
- Today
- Total
Do diffence
Softreference<> 를 이용한 singletone 구현 본문
com.android.contacts.model.Sources.java 에 구현한 예제
private static SoftReference<Sources> sInstance = null;
/**
* Requests the singleton instance of {@link Sources} with data bound from
* the available authenticators. This method blocks until its interaction
* with {@link AccountManager} is finished, so don't call from a UI thread.
*/
public static synchronized Sources getInstance(Context context) {
Sources sources = sInstance == null ? null : sInstance.get();
if (sources == null) {
sources = new Sources(context);
sInstance = new SoftReference<Sources>(sources);
}
return sources;
}
/**
* Requests the singleton instance of {@link Sources} with data bound from
* the available authenticators. This method blocks until its interaction
* with {@link AccountManager} is finished, so don't call from a UI thread.
*/
public static synchronized Sources getInstance(Context context) {
Sources sources = sInstance == null ? null : sInstance.get();
if (sources == null) {
sources = new Sources(context);
sInstance = new SoftReference<Sources>(sources);
}
return sources;
}