我们可以使用具有不同目的的单个FutureTask和Executor

时间:2016-11-10 10:11:29

标签: android threadpool

我使用newSingleThreadExecutor和执行器

Executor mSessionExecutor = Executors.newSingleThreadExecutor(); 

这是返回List的未来任务

FutureTask<List<String>> listFutureTask = new FutureTask<List<String>>(new Callable<List<Session>>() {
        @Override
        public List<String> call() throws Exception {
         return getSessions();
        }
    });

获取o / p我使用下面的代码

mSessionExecutor.execute(listFutureTask);
List<String> sessions= listFutureTask.get();

所以我的问题是我可以多次使用相同的未来任务 因为listFutureTask.get();返回运行第一个任务时始终存在的相同值

我可以使用吗?

 mSessionExecutor.execute(listFutureTask);
 mSessionExecutor.execute(listFutureTask); ..

多次,以便在调用listFutureTask.get();之后我将获得更新列表

0 个答案:

没有答案