汪汪一只猫
2018-08-27 21:55:51浏览 1185
/**
* 单例设计模式的一般定义:一个类中只允许有一个实例。*/
public class DownloadManager {
private static DownloadManager sManager;
public static DownloadManager getInstance() {
if (sManager == null) {
synchronized (DownloadManager.class) {
if (sManager == null) {
sManager = new DownloadManager();
}
}
}
return sManager;
}
public static class Holder {
private static DownloadManager sManager = new DownloadManager();
public static DownloadManager getInstance() {
return sManager;
}
}
private DownloadManager() {
}
}
原文链接:http://www.apkbus.com/blog-340477-76813.html