BlockingQueue queue = new LinkedBlockingQueue();
ThreadPoolExecutor ex = new ThreadPoolExecutor(1,1, 1L, TimeUnit.MINUTES, queue);
final HashMap responses = new HashMap();
ex.execute(new Runnable() {
@Override
public void run() {
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_MORE_FAVORABLE);
Response response = getService().getProducts();
responses.put("1",response);
}
});
....
....
...
ex.shutdown();
ex.awaitTermination(1000, TimeUnit.DAYS);
long time2 = System.currentTimeMillis();
我做了很多要求,我希望在完成后得到通知.
使用带有1个线程的ThreadPoolExecutor在旧设备上测试android 2.3 gingerbead需要1-1.2秒.使用4个线程需要更多4-5秒!
在星系标签3上进行测试需要一个线程100毫秒,4个需要60毫秒.
为什么会这样?