java - What change did really happen in Async Task after Android Gingerbread? -
what change did android team make in async task after android 2.3. when executed following code getting same result in both android 2.3 , 3.0.
package com.sample.asynctask; import android.app.activity; import android.os.asynctask; import android.os.bundle; import android.util.log; public class asynctasktestactivity extends activity { private static final string tag = "asynctasktestactivity"; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); //executorservice executorservice = executors.newfixedthreadpool(1); (int = 1; <= 20; i++) { testtask testtask = new testtask(i); testtask.execute(); } } private static class testtask extends asynctask<void, integer, void> { int i; public testtask(int i) { log.i(tag, "constructor " + i); this.i = i; } @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); log.i(tag, "onpreexecute " + i); } @override protected void doinbackground(void... params) { log.i(tag, + " thread goes sleep"); try { thread.sleep(20000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } log.i(tag, + " thread wakes up"); return null; } @override protected void onpostexecute(void result) { // todo auto-generated method stub super.onpostexecute(result); log.i(tag, "onpostexecute " + i); } } }
my assumption in gingerbread: 5 async task executes @ 1 thread pool @ time. assumption in honeycomb: 1 async task executes @ 1 thread pool @ time. concurrent execution.
but, both gingerbread , honeycomb executes 5 async tasks @ same time.
and when number async task increased 140.i not getting java.util.concurrent.rejectedexecutionexception
.
whether assumptions correct? happening inside there?
whether assumptions correct?
your assumptions correct, well, sort of.
what happening inside there?
the default executor inside android.os.asynctask:
... ... private static volatile executor sdefaultexecutor = serial_executor; ... ...
has been reset in android.app.activitythread:
... ... // if app honeycomb mr1 or earlier, switch asynctask // implementation use pool executor. normally, use // serialized executor default. has happen in // main thread main looper set right. if (data.appinfo.targetsdkversion <= android.os.build.version_codes.honeycomb_mr1) { asynctask.setdefaultexecutor(asynctask.thread_pool_executor); } ... ...
what change did happen in async task after android gingerbread?
check out asynctask change history, more specifically, one:
mar 17, 2011 - asynctask uses poll executor apps through hc mr1 , t…
when number async task increased 140, not getting java.util.concurrent.rejectedexecutionexception.
this factor of total number of tasks , execution time per each task, in world, total task number 140 (which bigger 128), however, total number of thread allocated threadpool @ given time smaller 128, in word, there idle threads (due last task finished , release resource) available in case. can try increase execution time per each task example thread.sleep(10000)
, give rejectedexecutionexception.
Comments
Post a Comment