package acr.browser.lightning.async;

import android.support.annotation.NonNull;
import android.util.Log;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;

/**
 * Created 9/27/2015 Anthony Restaino
 */
public class AsyncExecutor implements Executor {

    private static final String TAG = AsyncExecutor.class.getSimpleName();
    private static AsyncExecutor INSTANCE = new AsyncExecutor();
    private Queue<Runnable> mQueue = new ArrayDeque<>(1);
    private Executor mExecutor = Executors.newFixedThreadPool(4);

    private AsyncExecutor() {}

    public static AsyncExecutor getInstance() {
        return INSTANCE;
    }

    public synchronized void notifyThreadFinish() {
        if (mQueue.isEmpty()) {
            return;
        }
        Runnable runnable = mQueue.remove();
        execute(runnable);
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }

    @Override
    public void execute(@NonNull Runnable command) {
        try {
            mExecutor.execute(command);
        } catch (RejectedExecutionException ignored) {
            mQueue.add(command);
            Log.d(TAG, "Thread was enqueued");
        }
    }
}

@@ -191,16 +191,61 @@
 ecutor;%0A
+import java.util.concurrent.ExecutorService;%0A
 import j
@@ -275,16 +275,16 @@
 cutors;%0A
-
 import j
@@ -646,16 +646,23 @@
 Executor
+Service
  mExecut
@@ -1015,24 +1015,24 @@
   @Override%0A
-
     protecte
@@ -1068,16 +1068,49 @@
 wable %7B%0A
+        mExecutor.shutdownNow();%0A
         

Use executorservice instead of plain executor to facilitate shutdown