@Test public void testTimeWait() throws InterruptedException { TimeWaitLogger timeWaitLogger = new TimeWaitLogger(1000); AtomicLong atomicLong = new AtomicLong(); new Thread(()->{ while (true){ timeWaitLogger.logWithRunnable(atomicLong::incrementAndGet); } }).start(); Thread.sleep(1500); Assert.assertEquals(2L,atomicLong.get()); }
public void logWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (disabled) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } }
TimeWaitLogger { public void logWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (disabled) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } } }
TimeWaitLogger { public void logWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (disabled) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } } TimeWaitLogger(long waitTimeMills); }
TimeWaitLogger { public void logWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (disabled) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } } TimeWaitLogger(long waitTimeMills); void logWithRunnable(Runnable runnable); void logWithConsumer(Consumer<T> consumer, T t); void logWithBiConsume(BiConsumer<T, R> biConsumer, T r, R executor); }
TimeWaitLogger { public void logWithRunnable(Runnable runnable) { long currentTimeMillis = System.currentTimeMillis(); if (disabled) { runnable.run(); } else if (currentTimeMillis > lastLogTime + waitTime) { lastLogTime = currentTimeMillis; runnable.run(); } } TimeWaitLogger(long waitTimeMills); void logWithRunnable(Runnable runnable); void logWithConsumer(Consumer<T> consumer, T t); void logWithBiConsume(BiConsumer<T, R> biConsumer, T r, R executor);  }