Code example for ThreadPoolExecutor

0
 
    public ThreadPool() { 
        mExecutor = new ThreadPoolExecutor(
                CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME,
                TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
                new PriorityThreadFactory("thread-pool", 
                android.os.Process.THREAD_PRIORITY_BACKGROUND));
    } 
 
    // Submit a job to the thread pool. The listener will be called when the 
    // job is finished (or cancelled). 
    public <T> Future<T> submit(Job<T> job, FutureListener<T> listener) {
        Worker<T> w = new Worker<T>(job, listener);
        mExecutor.execute(w);
        return w;
    } 
 
    public <T> Future<T> submit(Job<T> job) {
        return submit(job, null);
    }