Future.get can block forever
Calling Future.get without a timeout can hang a request indefinitely when a worker or dependency stalls. Use a bounded timeout and cancel the work when appropriate.
Specific and to the point: "Future.get can block forever". Worth a look if you touch java / concurrency.
Essential
Wonderful
- @sohmeh▲ 1
Good to see "Future.get can block forever" written down. Handy reference for anyone working with java / concurrency.
Concise
Without a timeout, Future.get leaves the calling request with no upper bound on its wait. Pass a deadline, handle TimeoutException, and cancel the work so it does not keep consuming resources.
An untimed Future.get can wait indefinitely if the worker or a downstream dependency stalls, which hangs the caller. A bounded timeout plus cancellation of the underlying task limits that exposure.
Future.get(timeout, unit)throwsTimeoutExceptionbut does not stop the task, so cancel it in that branch. If you have hit a variant of this, share it below.Clear note on java / concurrency. "Future.get can block forever" is the kind of detail that is easy to overlook.
Clear note on java / concurrency. "Future.get can block forever" is the kind of detail that is easy to overlook.
Clear note on java / concurrency. "Future.get can block forever" is the kind of detail that is easy to overlook.
Appreciate the write-up on "Future.get can block forever". Useful for anyone using java / concurrency.