java - AsyncTask thread still there after execute, is that normal? -
java - AsyncTask thread still there after execute, is that normal? -
when utilize asynctasks checking in ddms, thread persist in memory waiting thread after onpostexecute() method, normal?. here simplified activity reproduces problem:
package com.example.async; import android.app.activity; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; public class asynctaskexampleactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); new exampleasynctask().execute(); } private class exampleasynctask extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { (int =0; i<50000;i++){ int j=i*2; } homecoming null; } protected void onpostexecute(void result) { log.d("test","end onpostexecute"); } } }
asynctask uses "thread pool" technique. each asynctask start gets queue; there idle threads in "pool" (or created needed limit) waiting tasks. idle thread pool takes asynctask , executes it, returns pool. process repeats until there no more tasks in queue.
this approach has 2 of import features:
no overhead creating thread every time in case of huge number of tasks scheme performance degrades gracefully: of tasks wait in queue , few of them executed @ time; of them executed. otherwise, if separate thread started each task, scheme run out of memory or threads, or tasks take forever finish.the thread see in ddms after asynctask finished idle thread in pool.
java android multithreading thread-safety android-asynctask
Comments
Post a Comment