Package Com.jredu.schooltong.manager;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
public class Executormanager {
1. Private constructors, providing static variables for storage, providing a static method
Private Executormanager () {
Init ();
}
static variables
private static Executormanager instance;
Static methods
public static Executormanager getinstance () {
if (instance = = null) {
Locking
Synchronized (Executormanager.class) {
if (instance = = null) {
Instance = new Executormanager ();
}
}
}
return instance;
}
Use singleton mode to ensure that only one instance can be instantiated
This class can be applied to other apps.
Private Executorservice Executorservice;
Initializing the thread pool
private void init () {
int threadcount = Runtime.getruntime (). Availableprocessors () * 2 + 1;
Executorservice = Executors
. Newfixedthreadpool (Math.min (ThreadCount, 8));
}
Public Executorservice Getexecutor () {
return this.executorservice;
}
public void execute (Runnable Runnable) {
This.executorService.execute (runnable);
}
}
Android Singleton thread pool