使用执行器服务进行繁重循环操作的最佳实践是什么?

问题描述 投票:0回答:0

我使用 Executor 来执行繁重的操作,例如使用循环对 JSON 响应进行分组。我使用了here的执行程序服务用法,并一直使用此代码进行后台操作:

private final Executor otherBackgroundOperationsExecutor = Executors.newFixedThreadPool(3);

我想知道这个技术是否正确。这是我的使用方法:

AppExecutors.getInstance().getOtherBackgroundOperationsExecutor().execute(new Runnable() {
        @Override
        public void run() {
            //heavy loop
        }
});

我一直在使用这种技术,但最近将其与 LinkedList 和分组一起使用时,我得到了一些意想不到的结果。

java android concurrency background-process executorservice
© www.soinside.com 2019 - 2024. All rights reserved.