This commit is contained in:
laoyuyu
2019-08-07 10:29:48 +08:00
parent 558c9e1223
commit 86c3003b29
5 changed files with 48 additions and 23 deletions

View File

@@ -52,6 +52,32 @@ public class ThreadTaskManager {
mExePool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
}
/**
* 删除所有线程任务
*/
public void removeAllThreadTask() {
if (mThreadTasks.isEmpty()) {
return;
}
try {
LOCK.tryLock(2, TimeUnit.SECONDS);
for (Set<FutureContainer> threads : mThreadTasks.values()) {
for (FutureContainer container : threads) {
if (container.future.isDone() || container.future.isCancelled()) {
continue;
}
container.threadTask.destroy();
}
threads.clear();
}
mThreadTasks.clear();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
LOCK.unlock();
}
}
/**
* 启动线程任务
*

View File

@@ -112,7 +112,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
}
}
ThreadTaskManager.getInstance().removeAllThreadTask();
mCachePool.clear();
}