code: public void unscheduleTask() {
      if (unschedule.compareAndSet(false, true)) {
        scheduledFuture.cancel(false);
        scheduledFuture = null;
      }
  
    }
docs: Unschedule task if active, and cancel thread to inform it must be interrupted in a proper way.