AsyncTask threads never die AsyncTask threads never die multithreading multithreading

AsyncTask threads never die


AsyncTask manages a thread pool, created with ThreadPoolExecutor. It will have from 5 to 128 threads. If there are more than 5 threads, those extra threads will stick around for at most 10 seconds before being removed. (note: these figures are for the presently-visible open source code and vary by Android release).

Leave the AsyncTask threads alone, please.


In addition to CommonsWare's response:

Currently I'm using Android 2.2, and my application uses no more than one AsyncTask at any time, but I'm creating a new one every x minutes. At first new AsyncTask Threads start to appear (a new Thread for a new AsyncTask) but after 5 threads (as mentioned by CommonsWare) they just stay visible in the debug window, and get re-used when new AsyncTask threads are needed. They just stay there until the debugger disconnects.


Same symptom here. In my case the threads hanged around after I'd killed the Activity, and I was hoping for the App to close completely. Problem partly solved by using a single threaded executor:

    myActiveTask.executeOnExecutor(Executors.newSingleThreadExecutor());

This made the thread to vanish after the completing its work.