Created
October 4, 2018 08:29
-
-
Save AmaranthLIS/67d3fb992b48746b426166fba7aff27a to your computer and use it in GitHub Desktop.
Strange thing with CompletableFuture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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