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

Discussion

Consider starting the same thread twice. Which statement is correct?

  • A.A second call to start() is ignored and returns without any effect.
  • B.A thread may be started once only; a second call to start() throws IllegalThreadStateException.
  • C.A thread may be started again once its run() method has returned normally.
  • D.A thread may be started any number of times provided it is not currently alive at the time of the call.

Answer: B

The javadoc is explicit that it is never legal to start a thread more than once, and that a thread may not be restarted once it has completed execution. The second call throws IllegalThreadStateException. Re-running work needs a fresh Thread object, or an executor that manages reuse for you.

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

Post your comment

Please log in or register to post a comment.