Skip to content

Instantly share code, notes, and snippets.

@AmaranthLIS
Created October 4, 2018 08:29
Show Gist options
  • Save AmaranthLIS/67d3fb992b48746b426166fba7aff27a to your computer and use it in GitHub Desktop.
Save AmaranthLIS/67d3fb992b48746b426166fba7aff27a to your computer and use it in GitHub Desktop.
Strange thing with CompletableFuture
System.out.println("CompletableFuture");
Future<String> foo = new CompletableFuture<>();
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
System.out.println("Guava SettableFuture");
foo = SettableFuture.create();
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
System.out.println("Spring SettableListenableFuture");
foo = new SettableListenableFuture<>();
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
System.out.println("Real Future");
foo = Executors.newSingleThreadScheduledExecutor().submit(() -> {
try {
Thread.sleep(TimeUnit.DAYS.toMillis(1));
} catch (InterruptedException e) {
//ignore
}
return "foo";
});
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment