package com.geolo.android.tea.system;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**线程池工具
* @author geolo*/
public class MyThreadPool extends ThreadGroup{
private static MyThreadPool myThreadPool;
private ThreadPoolExecutor mThreadPoolExecutor;
private static int number = 0;
public MyThreadPool(String name) {
this(Thread.currentThread().getThreadGroup(), name);
}
public MyThreadPool(ThreadGroup parent, String name) {
super(parent, name);
mThreadPoolExecutor = new ThreadPoolExecutor(2, 4, 3,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),
new ThreadPoolExecutor.DiscardOldestPolicy());
}
public static MyThreadPool getInstance(){
if(myThreadPool==null){
number ++;
myThreadPool = new MyThreadPool(number+"");
}
return myThreadPool;
}
public void Executor(Runnable runnable){
//mThreadPoolExecutor.execute(runnable);
mThreadPoolExecutor.execute(runnable);
}
}
我自己通用的线程池
最新推荐文章于 2024-09-05 10:39:00 发布