适用于Android的线程池
#工具类
/**
* @author yawei
*/
public class AppExecutors {
private static final String TAG = "AppExecutors";
/**磁盘IO线程池**/
private final ExecutorService diskIO;
/**网络IO线程池**/
private final ExecutorService networkIO;
/**UI线程**/
private final Executor mainThread;
/**定时任务线程池**/
private final ScheduledExecutorService scheduledExecutor;
private volatile static AppExecutors appExecutors;
public static AppExecutors getInstance() {
if (appExecutors == null) {
synchronized (AppExecutors.class) {
if (appExecutors == null) {
appExecutors = new AppExecutors();
}
}
}
return appExecutors;
}
public AppExecutors(ExecutorService diskIO, ExecutorService networkIO, Executor mainThread, ScheduledExecutorService scheduledExecutor) {
this.diskIO = diskIO;
this.networkIO = networkIO;
this.mainThread = mainThread;
this.scheduledExecutor = scheduledExecutor;
}
public AppExecutors() {
this(diskIoExecutor()