### Question:
SequentialExecutor implements Executor { @Override public void execute(Runnable command) { boolean needExecute; synchronized (myWorkQueue) { myWorkQueue.add(command); if (myPending) { needExecute = false; } else { needExecute = true; myPending = true; } } if (needExecute) { myExecutor.execute(myTask); } } SequentialExecutor(Executor executor); @Override void execute(Runnable command);  }### Answer:
@Test public void test() throws InterruptedException { if (StringUtils.isEmpty(System.getenv("SLOW_MACHINE"))) { final ExecutorService actualExecutor = Executors.newFixedThreadPool(5); SequentialExecutor executor = new SequentialExecutor(actualExecutor); int count = 100; TestRunnable[] arr = new TestRunnable[count]; for (int index = 0; index < count;) { arr[index++] = new TestRunnable(); } for (int index = 0; index < count;) { executor.execute(arr[index++]); } executor.execute(new Runnable() { @Override public void run() { actualExecutor.shutdown(); } }); actualExecutor.awaitTermination(1L, TimeUnit.SECONDS); for (int index = 1; index < count; ++index) { Assert.assertTrue("Runnable at index " + (index - 1) + " did not run", arr[index - 1].getRunStop() > 0L); Assert.assertTrue("Start time at index " + index + " [" + arr[index].getRunStart() + "] should have been >= stop time of index " + (index - 1) + " [" + arr[index - 1].getRunStop() + "]", arr[index].getRunStart() >= arr[index - 1].getRunStop()); } } }