class ThreadInterruptedCompletableFuture extends CompletableFuture<R> {

    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        cancel = true;

        if (this.isDone() || this.isCompletedExceptionally()) {
            LOGGER.warn("Can not be canceled because the caller future isDone or isCompletedExceptionally");
            return false;
        }

        while (thread == null) {
            try {
                LOGGER.warn("Waiting 1s for taskThread to be set...");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                LOGGER.warn(e.toString(), e);
                Thread.currentThread().interrupt();
                return false;
            }
        }

        thread.interrupt();
        return true;
    }

}