上干货:
/**
* 线程池
*/
public class ThreadPoolUtil {
private static ThreadPoolExecutor threadPool;
private static Handler handler = new Handler(Looper.getMainLooper());
public static void runOnSubThread(Runnable r) {
getThreadPool().execute(r);
}
public static void runOnUIThread(Runnable runnable){
handler.post(runnable);
}
/**
* dcs获取线程池
* @return 线程池对象
*/
public static ThreadPoolExecutor getThreadPool() {
if (threadPool != null) {
return threadPool;
} else {
synchronized (ThreadPoolUtil.class) {
int corePoolSize = 2;// 核心线程数
int maximumPoolSize = 5;// 最大线程数
long keepAliveTime = 60;// 休息时间
if (threadPool == null) {
threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,