
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

class Ideone {
    public static void main (String[] args) throws Exception {
        Thread.currentThread().interrupt();

        try {
            CompletableFuture.runAsync(() -> interruptibleComputation())
                .whenComplete((r, t) -> System.out.println("foo")).get();
        }
        finally {
            // Prevent the JVM from terminating immediately (which would release the resources anyway
            Thread.sleep(4000);
        }
        
    }

    static void interruptibleComputation() {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ex) {
            // will never happen, as CompletableFuture does not support interruption
            ex.printStackTrace();
        }
    }
}