执行者服务被拒绝

时间:2019-03-04 09:40:46

标签: android executorservice max-pool-size

我正在使用ScheduledExecutorService进行一些后台任务。但是有时我会在crashlytics上报告此错误:

Fatal Exception: java.util.concurrent.RejectedExecutionException
Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@3ff6c29 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@76bbbae[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 531]

这是我初始化池的方法:

if (backgroundExecutorService == null) {
            backgroundExecutorService = Executors.newScheduledThreadPool(5);
        }

这是我完成工作后关闭它的方式:

if (backgroundExecutorService != null)
            backgroundExecutorService.shutdownNow();
        backgroundExecutorService = null;

因为它显示池大小为0,活动线程为0,已排队的任务为0,已完成的任务为531。现在如何调试此问题以及如何解决该问题?

0 个答案:

没有答案