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

Discussion

Which of these statements about why Thread.stop() is deprecated is correct?

  • A.stop() is unsafe because it may leave the thread's monitors permanently locked.
  • B.stop() is unsafe because it cannot interrupt a thread that is blocked waiting to acquire a monitor lock.
  • C.stop() is unsafe only when called on a daemon thread.
  • D.stop() is unsafe because it unlocks every monitor the thread held, exposing half-updated objects.

Answer: D

The javadoc explains that stopping a thread unlocks all of the monitors it had locked, so any object left in an inconsistent state by the half-finished work becomes visible to other threads, giving arbitrary behaviour. The damage is to shared data, not to the locks themselves.

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

Post your comment

Please log in or register to post a comment.