What are the states associated in the thread

Thread contains ready, running, waiting and dead states.

In Java, a thread can be in one of the following states:

  1. New: When a thread is created but not yet started, it is in the new state.
  2. Runnable: A thread that is ready to run is moved to the runnable state. It can be waiting for its turn to be picked for execution by the thread scheduler.
  3. Blocked: A thread that is blocked is waiting for a monitor lock to enter a synchronized block/method or waiting to reenter a synchronized block/method after calling Object.wait().
  4. Waiting: A thread that is waiting is in this state because it is waiting for another thread to perform a particular action. It transitions to the runnable state when that action is performed by another thread.
  5. Timed Waiting: A thread can be in this state when it is waiting for another thread to perform a particular action within a stipulated amount of time. It transitions to the runnable state when that time elapses.
  6. Terminated: A thread that has exited is in this state.

These states are defined by the Thread.State enum in Java. You can access the current state of a thread using the Thread.getState() method. Keep in mind that the exact behavior can depend on the version of Java you are using, as the threading model and its implementation may evolve with different Java versions.