• August 29, 2014
  • Core Java
  • Comments Off on Thread life cycle in java

Thread life cycle in java

Thread life cycle:

  1. 1. New.
  2. 2. Runnable.
  3. 3. Running.
  4. 4. Blocked(Non-Runnable).
  5. 5. Dead.

Diagram:

thread life cycle

 

1. New: A new thread is created but not working. A thread after creation and before invocation of start() method will be in new state.

2. Runnable: A thread after invocation of start() method will be in runnable state. A thread in runnable state will be available for thread scheduler.

3. Running: A thread in execution after thread scheduler select it, it will be in running state.

4. Blocked: A thread which is alive but not in runnable or running state will be in blocked state. A thread can be in blocked state because of suspend(), sleep(), wait() methods or implicitly by JVM to perform I/O operations.

5. Dead: A thread after exiting from run() method will be in dead state. We can use stop() method to forcefully killed a thread.
 
Next Topic: Multithreading in java.
Previous Topic: Commonly used exception methods of Throwable class in java.

Related Topics:

Multithreading in java.
Thread life cycle in java.
Way of creating thread in java.
Commonly used methods of Thread class.
Thread scheduling in java with example.
Thread priority in java with example.
Naming a thread in java with example.
Joining a thread in java with example.
Daemon thread in java with example.
Can we start a thread twice?
Can we call run method directly?
Difference between Thread.yield() and Thread.sleep() methods.
Deadlock in java with example.
Starvation in java with example.
Inter-thread communication in java with example.
Synchronization in java with example.
Synchronized method in java with example.
Static synchronization in java with example.
Synchronized block in java with example.

 


Comments are closed.