class SerialExecutor implements Executor {
  final Queue<Runnable> tasks = new LinkedBlockingDeque<>();
  final Executor executor;
  Runnable active;
  private volatile boolean shutdown;
  private Thread thread;
  private final Object threadLock = new Object();

  public SerialExecutor(Executor executor) {
    this.executor = executor;
  }

  @Override
  public synchronized void execute(final Runnable r) {<FILL_FUNCTION_BODY>}

  protected synchronized void scheduleNext() {
    if ((active = tasks.poll()) != null) {
      executor.execute(active);
    }
  }

  /**
   * Shutdown the executor without executing any more tasks.
   * <p>
   * The the current task will be interrupting if it is not the thread that initiated the shutdown.
   */
  public void shutdownNow() {
    this.shutdown = true;
    tasks.clear();
    synchronized (threadLock) {
      if (thread != null && thread != Thread.currentThread()) {
        thread.interrupt();
      }
    }
  }

  public boolean isShutdown() {
    return shutdown;
  }
}

    if (shutdown) {
      throw new RejectedExecutionException();
    }
    tasks.offer(() -> {
      try {
        if (shutdown) {
          return;
        }
        synchronized (threadLock) {
          thread = Thread.currentThread();
        }
        r.run();
      } catch (Throwable t) {
        thread.getUncaughtExceptionHandler().uncaughtException(thread, t);
      } finally {
        synchronized (threadLock) {
          thread = null;
        }
        Thread.interrupted();
        scheduleNext();
      }
    });
    if (active == null) {
      scheduleNext();
    }
  
<no_super_class>