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

Discussion

Consider reusing a Thread object after run() has finished. Which statement is correct?

  • A.A thread that has finished can be restarted once its interrupt status is cleared.
  • B.A thread that has finished cannot be restarted; a new Thread object is needed.
  • C.A thread that has finished returns to the NEW state and can be started again.
  • D.A thread that has finished can be restarted by calling run() and then start().

Answer: B

A finished thread is TERMINATED, and the javadoc states a thread may not be restarted once it has completed execution; a second start() throws IllegalThreadStateException. Reusing the object is impossible, which is one reason executors exist: they reuse threads while you submit fresh tasks.

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

Post your comment

Please log in or register to post a comment.