Java FutureTask.cancel()

Java FutureTask.cancel() is a method in the Java FutureTask class that attempts to cancel the execution of a task. If the task has not yet started or is still running, it will be stopped, and the task is marked as canceled. Introduced in Java 2004 with Java 5, cancel() is crucial for managing asynchronous tasks in Java applications where early termination of a task may be necessary, such as in resource-constrained environments or with user-initiated actions.

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/FutureTask.html