public OCThreadExecutor(int maxRunningThread, String poolName) {
super(maxRunningThread, maxRunningThread, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new OCThreadFactory(poolName));
runnableMap = new HashMap<>();
}
以上是自定义线程池,带参的构造方法;
static class OCThreadFactory implements ThreadFactory {
private final String name;
public OCThreadFactory(String name) {
this.name = name;
}
public String getPoolName() {
return name;
}
@Override
public Thread newThread(@NonNull Runnable r) {
return new OCThread(r, name);
}
}
static class OCThread extends Thread {
public OCThread(Runnable runnable, String name) {
super(runnable, name);
setName(name);
}
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
super.run();
}
}
实现线程工厂;
重点来了:
/**
* 执行任务
* @param task 任务对象
* @param tag 任务唯一TAG
*/
public void submit(FutureTask task , String tag){