guava/src/com/google/common/util/concurrent/InterruptibleTask.java
final void interruptTask() {
    // Since the Thread is replaced by DONE before run() invokes listeners or returns, if we succeed
    // in this CAS, there's no risk of interrupting the wrong thread or interrupting a thread that
    // isn't currently executing this task.
    Runnable currentRunner = get();
    if (currentRunner instanceof Thread && compareAndSet(currentRunner, INTERRUPTING)) {
      // Thread.interrupt can throw aribitrary exceptions due to the nio InterruptibleChannel API
      // This will make sure that tasks don't get stuck busy waiting.
      // Some of this is fixed in jdk11 (see https://bugs.openjdk.java.net/browse/JDK-8198692) but
      // not all.  See the test cases for examples on how this can happen.
      try {
        ((Thread) currentRunner).interrupt();
      } finally {
        Runnable prev = getAndSet(DONE);
        if (prev == PARKED) {
          LockSupport.unpark((Thread) currentRunner);
        }
      }
    }
  }
final void interruptTask() {
    // Since the Thread is replaced by DONE before run() invokes listeners or returns, if we succeed
    // in this CAS, there's no risk of interrupting the wrong thread or interrupting a thread that
    // isn't currently executing this task.
    Runnable currentRunner = get();
    if (currentRunner instanceof Thread && compareAndSet(currentRunner, INTERRUPTING)) {
      // Thread.interrupt can throw aribitrary exceptions due to the nio InterruptibleChannel API
      // This will make sure that tasks don't get stuck busy waiting.
      // Some of this is fixed in jdk11 (see https://bugs.openjdk.java.net/browse/JDK-8198692) but
      // not all.  See the test cases for examples on how this can happen.
      try {
        ((Thread) currentRunner).interrupt();
      } finally {
        Runnable prev = getAndSet(DONE);
        if (prev == PARKED) {
          LockSupport.unpark((Thread) currentRunner);
        }
      }
    }
  }
Interrupts the running task. Because this internally calls {@link Thread#interrupt()} which can
in turn invoke arbitrary code it is not safe to call while holding a lock.