Skip to content
Sharp

Networking · interview question

How can you ensure a CompletableFuture computation times out if it takes too long?

Multiple choiceMediumchapter-11-curatedpremiumnetworkingasynchronous-http
Choose one answer
Answer and explanation

Correct answer

C. Use completeOnTimeout

Why

The completeOnTimeout method allows you to specify a timeout duration after which a default value will be returned if the original computation has not completed. This is useful for handling cases where the computation may hang indefinitely.

Test yourself on Networking

A free test with instant, explained results. No account needed.

Start free test
All Networking questions →