views:

90

answers:

2

Hi, While working on an an application i noticed that the thread count keeps growing all the time AsyncTask Threads remain open for some reason (im sure they finished proccesing and exited) i have no idea why i keep creating more threads of this type and they keep running indefinitely. is there any way to verify that these threads are terminated on complition? are there any known issues with AsyncTasks threads remaing open?

When running this:

public  class DoNothingTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            return null;
        }

    }

i see in the debbuger a new thread for each time i do new DoNothingTask().execute(null); as folows

Thread[<ThreadNumber>AsyncTask#1](running)

, my question is why is this? my application relies allot on AsyncTask and i cant have a new thread created and stay alive after each task.

Thanks, Totem

A: 

You should use

thread.join

to be sure that a thread completes. Are you doing this?

bradgonesurfing
Dont think this is applicable for AsyncTask().
totem
+1  A: 

I am not sure if this is related, but i faced similar issue in one of my applications too.

I have an activity which initializes TimerTask threads. The tasks get executed properly at the interval specified, but after some idle time, the number of these threads seem to be increased (showing that the threads remained open and new threads get created). The problem was dynamic loading and unloading of my application by Android VM. The original threads never used to get killed where as on every new load of application, the thread initialization used to happen. This is why total number of threads in my application used to rise.

Is there a similar implementation in your application as well.

Tushar Tarkas
nope, im not creating the threads on creating AsyncTasks which are one shot anyway.
totem