FileDocCategorySizeDatePackage
ProviderExecutor.javaAPI DocAndroid 5.1 API3591Thu Mar 12 22:22:40 GMT 2015com.android.documentsui

ProviderExecutor

public class ProviderExecutor extends Thread implements Executor

Fields Summary
private static HashMap
sExecutors
private final LinkedBlockingQueue
mQueue
private final ArrayList
mPreemptable
private Executor
mNonPreemptingExecutor
Constructors Summary
Methods Summary
public voidexecute(android.os.AsyncTask task, P params)
Execute the given task. If given task is not {@link Preemptable}, it will preempt all outstanding preemptable tasks.

        if (task instanceof Preemptable) {
            synchronized (mPreemptable) {
                mPreemptable.add(new WeakReference<Preemptable>((Preemptable) task));
            }
            task.executeOnExecutor(mNonPreemptingExecutor, params);
        } else {
            task.executeOnExecutor(this, params);
        }
    
public voidexecute(java.lang.Runnable command)


    
        
        preempt();
        Preconditions.checkNotNull(command);
        mQueue.add(command);
    
public static com.android.documentsui.ProviderExecutorforAuthority(java.lang.String authority)


         
        synchronized (sExecutors) {
            ProviderExecutor executor = sExecutors.get(authority);
            if (executor == null) {
                executor = new ProviderExecutor();
                executor.setName("ProviderExecutor: " + authority);
                executor.start();
                sExecutors.put(authority, executor);
            }
            return executor;
        }
    
private voidpreempt()


       
        synchronized (mPreemptable) {
            int count = 0;
            for (WeakReference<Preemptable> ref : mPreemptable) {
                final Preemptable p = ref.get();
                if (p != null) {
                    count++;
                    p.preempt();
                }
            }
            mPreemptable.clear();
        }
    
public voidrun()

        while (true) {
            try {
                final Runnable command = mQueue.take();
                command.run();
            } catch (InterruptedException e) {
                // That was weird; let's go look for more tasks.
            }
        }