Here you can find the source of cancel(final Future> future)
private static boolean cancel(final Future<?> future)
//package com.java2s; //License from project: Apache License import java.util.concurrent.Future; public class Main { private static boolean cancel(final Future<?> future) { return future.isDone() || future.isCancelled() || future.cancel(true); }/*w w w. jav a 2s . c o m*/ public static boolean cancel(final Future<?> future, final boolean mayInterruptIfRunning) { return (future != null) && future.cancel(mayInterruptIfRunning); } public static boolean isDone(final Future<?> future) { return (future != null) && future.isDone(); } public static boolean isCancelled(final Future<?> future) { return (future != null) && future.isCancelled(); } }