code: public void runPendingCommands() {
          List<Runnable> commandsToRun = commands;
          commands = new ArrayList<Runnable>();
      
          for (Runnable command: commandsToRun) {
              command.run();
          }
      }
docs: Runs all commands that are currently pending. If those commands also
  schedule commands for execution, the scheduled commands will <em>not</em>
  be executed until the next call to {@link #runPendingCommands()} or
  {@link #runUntilIdle()}.