When does a Java Thread reach the 'Die' State

后端 未结 4 670
既然无缘
既然无缘 2020-11-30 05:04

In Java, Die is one of the states on a thread.

What causes a thread to enter this state?

相关标签:
4条回答
  • 2020-11-30 05:08

    From the Thread API, here is a complete list:

    • If the run() method returns.
    • If an exception is thrown that propagates beyond the run method.
    • If it is a daemon thread and all non-daemon threads have 'died'
    • If the exit method of class Runtime has been called (even at another thread).
    0 讨论(0)
  • 2020-11-30 05:26

    There are two ways for a thread to die:

    a) It could die of natural causes which is when the run() method finishes or return,

    or

    b) it could be kill by using the stop() method or when something goes wrong with the program(This could be an Exception) or computer.

    0 讨论(0)
  • 2020-11-30 05:32

    All Threads die either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.

    0 讨论(0)
  • 2020-11-30 05:34

    Threads die in the following situations:

    1. When the method it runs finishes (or throws)
    2. When the process is terminated
    3. When the computer is turned off or reset.
    0 讨论(0)
提交回复
热议问题