Code example for Executor

Methods: execute

0
 
    // 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);
    } 
 
    private class Worker<T> implements Runnable, Future<T>, JobContext {
        private static final String TAG = "Worker";
        private Job<T> mJob;
        private FutureListener<T> mListener;
        private CancelListener mCancelListener;
        private ResourceCounter mWaitOnResource;
        private volatile boolean mIsCancelled;
        private boolean mIsDone;