String (@NotNull Object event) { int eventsPosted = myEventsPosted.incrementAndGet(); boolean shouldLog = false; if (eventsPosted > myEventCountThreshold) { synchronized (myEventsPosted) { if (myEventsPosted.get() > myEventCountThreshold) { long timeNow = System.currentTimeMillis(); shouldLog = timeNow - myStartedCounting < myTimeSpanMs; myEventsPosted.set(0); myStartedCounting = timeNow; } } } return shouldLog ? generateMessage(event, eventsPosted) : null; }