Android: AsyncTask OR normal Java threads with ExecutorService

advertisements

My application uses a Service to do some background stuff. I am using additional threads in the service to do some computation. For this purpose I create two threads every 5 to 10 seconds, which are running 5 to 10 seconds. But I don't know which thread-model I should use:

  1. AsyncTask:

    Pros:

    • easy to use
    • android specific
    • easy UI-interaction

    Cons:

    • Since I have to use API level 10, there is no ExecutorService with fixed thread pool to execute the AsyncTasks
  2. Normal Java Threads:

    Pros:

    • ExecutorService with fixed thread pool

    Cons:

    • Not so easy to handle, e.g. UI-interaction

Which model is better to use? Especially in concern of performance. Is there a heavy overhead when i am using AsyncTasks, and is the ExecutorService faster in reusing the threads than Android in creating new AsyncTasks?


If you look at the implementation of AsyncTask, you will see that it uses its own thread pool using "normal Java threads".

Is there a heavy overhead when i am using AsyncTasks, and is the ExecutorService faster in reusing the threads than Android in creating new AsyncTasks?

There should be no substantial difference between the two.