32

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

What causes a thread to enter this state?

johnc
  • 39,385
  • 37
  • 101
  • 139
Johanna
  • 27,036
  • 42
  • 89
  • 117

4 Answers4

52

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).
idrosid
  • 7,983
  • 5
  • 44
  • 41
3

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

Rob
  • 2,148
  • 13
  • 17
1

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.

Cesar Hermosillo
  • 942
  • 7
  • 19
0

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.
Spencer Ruport
  • 34,865
  • 12
  • 85
  • 147