Files
java-core-examples/completablefuture/output/05-timeouts-and-cancel.txt
T

18 lines
728 B
Plaintext

== 1. orTimeout: the future fails, the task keeps running
join() after 100 ms: CompletionException <- cause TimeoutException: null
task finished right after that? false
task finished 700 ms later? true
== 2. completeOnTimeout: a fallback value instead of an exception
join() returned: fallback value
== 3. cancel(true) does not interrupt the task either
cancel(true) returned: true
join(): CancellationException
task saw an interrupt? false
task ran to the end anyway? true
== 4. The fix: keep the executor's Future and cancel THAT on timeout
join(): CompletionException <- cause TimeoutException: null
task saw an interrupt? true