If you have an @Async method the returns a CompletableFuture
....and the future never gets completed, does spring just leak the thread? Yes, I know whomever is waiting on the results could timeout and assume exceptional completion for latter stages.....but that doesn't stop the thread. Even if you call cancel
, it doesn't do shit to the running thread:
from the docs:
@param mayInterruptIfRunning this value has no effect in this implementation because interrupts are not used to control processing.
If I use Future instead of CompletableFuture, cancel
will interrupt the thread. Unfortunately, there is no equivalent of "allOf" on Future like we have on CompletableFuture to wait for all the tasks, like so:
// wait for all the futures to finish, regardless of results
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new))
// if exceptions happened in any future, swallow them
// I don't care because I'm going to process each future in my list anyway
// we just wanted to wait for all the futures to finish
.exceptionally(ex -> null);
- how are we supposed to cancel a thread that we bailed on?
- if I didn't cancel it (somehow), would my pool just be down a thread forever????