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

Discussion

Which of these statements about what happens to a daemon thread at shutdown is correct?

  • A.A daemon thread is always allowed to finish run() before the JVM exits.
  • B.A daemon thread is given a fixed grace period to finish once the last non-daemon thread ends.
  • C.A daemon thread prevents the JVM from exiting while it holds a lock.
  • D.A daemon thread may be terminated at shutdown without its run() method finishing.

Answer: D

Because the JVM exits as soon as only daemons remain, a daemon can stop anywhere, including part-way through updating shared state or writing a file. No grace period is promised and holding a lock does not help. Work that must complete belongs on a non-daemon thread.

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

Post your comment

Please log in or register to post a comment.