简体   繁体   中英

Parallel Executing of an AsyncTask

In parallel executing of an asynctask, I find out 2 ways:

First one using THREAD_POOL_EXECUTOR :

myTask.executeOnExecutor ( AsyncTask.THREAD_POOL_EXECUTOR );

Second one using AsyncTaskCompat.executeParallel :

AsyncTask asyncTaskTest = new myTask();
AsyncTaskCompat.executeParallel ( asyncTaskTest , null );

Is there any difference between them?

If the device runs on Honeycomp or above, then there is no difference.

Below Api 11, the tasks will execute serially from api 1 to (exlusive) DONUT and run back in parellel from DONUT to Honeycomp.

So:

API 1 - 3: serially on a single background thread

API 4 - 11: parallel with pool of threads

API 12- x: uses executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);

Depending on your minimum API level, you could just use executeOnExecutor() directly from AsyncTask .

AsyncTaskCompat.executeParallel ( asyncTaskTest , null ); has been deprecated found in this Link .

Using ThreadPoolExecutor you can achieve Parallel Execution since you can pass ThreadFactory which helps is creation of Object Link

Since the later has more robust functionality compared to the first. It is better to move with the later and the Developer blocks also suggests so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM