Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about what Future.get() returns, and when it returns is true?

  • A.Future.get() blocks until the task completes, then returns its result or rethrows its exception.
  • B.Future.get() returns null immediately if the task has not finished, then must be polled until it does.
  • C.Future.get() returns a partial result if the task is still running.
  • D.Future.get() cancels the task if it has not yet started.

Answer: A

get() waits for completion and then delivers the outcome, wrapping a task failure in ExecutionException so the caller sees it on their own thread. That is the mechanism by which a value or an error crosses from the worker back to the submitter, which a bare Runnable cannot do.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.