add AsyncTask In Pool - Android android.os

Android examples for android.os:AsyncTask

Description

add AsyncTask In Pool

Demo Code


import android.os.AsyncTask;
import android.os.Build;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main{
    private static final Executor threadPoolExecutor = new ThreadPoolExecutor(
            corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,
            workQueue);/*www.  j a  v  a2  s.  c  o m*/
    public static void addTaskInPool(AsyncTask asyncTask) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            asyncTask.executeOnExecutor(threadPoolExecutor, null);
        } else {
            asyncTask.execute();
        }
    }
}

Related Tutorials