### Question:
TimeWaitRunner { public void doWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (runImmediately) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { synchronized (this) { if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } } } } TimeWaitRunner(long waitTimeMills);  TimeWaitRunner(long waitTimeMills, boolean runImmediately); void doWithRunnable(Runnable runnable);  }### Answer:
@Test public void testTimeWait() throws InterruptedException { TimeWaitRunner timeWaitLogger = new TimeWaitRunner(1000); AtomicLong atomicLong = new AtomicLong(); new Thread(()->{ while (true){ timeWaitLogger.doWithRunnable(atomicLong::incrementAndGet); } }).start(); Thread.sleep(1500); Assert.assertEquals(2L,atomicLong.get()); }