void () { var currentlySleeping = SLEEPING_INDEXERS.get(); var couldBeSleeping = currentlySleeping + 1; int writesInQueueToSleep = MAX_ALLOWED_WRITES_IN_QUEUE_PER_INDEXER * myNumberOfIndexingThreads + couldBeSleeping * MAX_ALLOWED_WRITES_IN_QUEUE_PER_INDEXER; var writesInQueue = INDEX_WRITES_QUEUED.get(); if (writesInQueue > writesInQueueToSleep && SLEEPING_INDEXERS.compareAndSet(currentlySleeping, couldBeSleeping)) { var writesToWakeUp = writesInQueueToSleep - MAX_ALLOWED_WRITES_IN_QUEUE_PER_INDEXER; LOG.debug("Sleeping indexer: ", couldBeSleeping, " of ", myNumberOfIndexingThreads, "; writes queued: ", writesInQueue, "; wake up when queue shrinks to ", writesToWakeUp); var napTimeNs = MAX_ALLOWED_WRITES_IN_QUEUE_PER_INDEXER * EXPECTED_SINGLE_WRITE_TIME_NS; sleepUntilUpdatesQueueIsShrunk(writesToWakeUp, napTimeNs); } }