code: void scheduleAfterWrite() {
      for (;;) {
        switch (drainStatus()) {
          case IDLE:
            casDrainStatus(IDLE, REQUIRED);
            scheduleDrainBuffers();
            return;
          case REQUIRED:
            scheduleDrainBuffers();
            return;
          case PROCESSING_TO_IDLE:
            if (casDrainStatus(PROCESSING_TO_IDLE, PROCESSING_TO_REQUIRED)) {
              return;
            }
            continue;
          case PROCESSING_TO_REQUIRED:
            return;
          default:
            throw new IllegalStateException();
        }
      }
    }
docs: Conditionally schedules the asynchronous maintenance task after a write operation. If the
  task status was IDLE or REQUIRED then the maintenance task is scheduled immediately. If it
  is already processing then it is set to transition to REQUIRED upon completion so that a new
  execution is triggered by the next operation.