【发布时间】:2017-04-01 13:44:11
【问题描述】:
在应用程序启动时,我正在进行网络调用(resttemplate Get 调用)以获取数据。
场景是这样的,
1)返回令牌列表(ID)的父调用
2)一旦我得到了令牌(Id)列表,我会遍历它,对每个令牌(Id)进行网络调用以获取数据。
我这样做的目的:
1)我已使用 Intent 服务进行父网络调用以获取列表令牌(ID)。
2)一旦我得到列表令牌(Id's),我就启动了我的 AsyncTask executeOnExecutor,通过构造函数将令牌列表(ID's)传递给 asynctask 并启动 AsyncTask 执行器。 像这样的,
MyAsyncExecutorTask executorTask = new MyAsyncExecutorTask(List<Integer> of tokens);
executorTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,(Void[]) null);
而在 MyAsyncExecutorTask 这就是我正在做的事情。
protected Void doInBackground(Void...params) {
//Settimg max priority
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
for (int i = 0; i < scheduleList.size(); i++) {
ScheduleImpl scheduleImpl = new ScheduleImpl();
//Making network call to get data using token
scheduleImpl.getData(scheduleList(i));
}
}
它应该正常工作。
我的疑问或问题是:
1) 我是否以正确的方式使用 Async executeOnExecuter()(我想进行并行网络调用)。从 AsyncTask execute() 切换到 Async executeOnExecuter() 后,我没有看到任何巨大的性能提升。
2)如何检查有多少工作线程正在运行。
【问题讨论】:
标签: java android multithreading android-asynctask threadpoolexecutor