jax
jax

Reputation: 38593

Using ThreadPoolExecutor and AsyncTask

When using ThreadPoolExecutor can I use AsyncTask as the Runnable in my queue? Or does this defeat the purpose?

//A holder for various tasks
private final LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(5);

//Thread Pool Executor
private final ThreadPoolExecutor tpe = new ThreadPoolExecutor(3, 3, 10, TimeUnit.SECONDS, queue);

Upvotes: 3

Views: 3878

Answers (2)

Jose L Ugia
Jose L Ugia

Reputation: 6250

Here is a nice approach if you need to manage your own task in a more custom way. Use queues and executors, the pass runnables or callables to them. http://ugiagonzalez.com/2012/07/02/theres-life-after-asynctasks-in-android/

Upvotes: 0

Moritz
Moritz

Reputation: 10352

An AsyncTask is not a Runnable so you can't really use that.

Upvotes: 6

Related Questions