在Executors.newFixedThreadPool完成其工作后

时间:2017-11-25 10:47:44

标签: android android-thread

我有一个方法。在这个方法中,我运行Executors的任务。它的工作是从服务器获取数据并填写结果Arraylist。

   public Paginator(String secSrv, int total, ExecutorService executorService, Cookie cookie) {
    securitySrv = secSrv;
    totalItems = total;
    this.executorService = executorService;
    this.cookie = cookie;
}

ArrayList<Suser> results = new ArrayList<>();

public ArrayList<Suser> generatePage(int currentPage) {

    fetchAllUsers(currentPage);
    ......
    for (int i = startItem; i < startItem + numOfData; i++) {
            pageData.add(results.get(i-1));
        }

填写结果后Arraylist我必须使用这个arraylist.how coud我知道executorService在哪里完成了它的工作,我可以继续我的方法吗?

   private void fetchAllUsers(final int currentPage) {

    Runnable fetchUserListFromSrv = new Runnable() {
        @Override
        public void run() {
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            JSONObject count = new JSONObject();
            try {
                count.put("count", 10);
                count.put("page", currentPage);
                String SearchUsersPagingResult = ...
                results.addAll(susers) ;
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    };

    executorService.submit(fetchUserListFromSrv);
}

1 个答案:

答案 0 :(得分:1)

使用文档。所有答案都在这里。

Future| Android developers

ExecutorService| Android developers