Tuesday, December 10, 2013

Thread States

When you look at a thread dump or a well structured thread dump using an analyzer you should see threads having a particular format along with its thread states both of which are detailed below -

Threads with format should be analyzed- ajp-10.10.50.23-8009-5 daemon prio=10

Meaning -

ajp - protocol we use to connet Apache to JBoss
10.10.XX.XXX - JBoss Server IP
8009 - Port on which the JBoss AJP port is listening
5 - Thread number.
daemon - its a daemon thread 
prio=10 - Represents the priority of the threads.

Java 6 Thread States and Life Cycle -

1) New - is the thread state for a thread which was created but has not yet started.

2) Runnable - A thread in the runnable state is executing from the JVM point of view but in fact it may be waiting for some resources from the operating system. The thread is occupying the CPU and processing a task

3) Timed waiting is a thread state for a thread waiting with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time: Thread.sleep(sleeptime), Object.wait(timeout), Thread.join(timeout), LockSupport.parkNanos(timeout), LockSupport.parkUntil(timeout)

4) Waiting - A thread is in the waiting state due to the calling one of the following methods Object.wait(), Thread.join(), LockSupport.park() without timeout

5) Blocked - Thread is in the blocked state while waiting for the monitor lock to enter a synchronized block or method or to reenter a synchronized block or method after calling Object.wait().

6) Terminated - After thread has completed execution of run() method, it is moved into terminated state

Other notes - 
Waiting on Monitor:
The thread is either sleeping or waiting on an object for said period of time or waiting to be notified by another thread. This will happen when any of the sleep() methods on Thread object or wait() method on an Object is called.

BLOCKED / WAITING FOR MONITOR ENTRY:
 Thread enters this state when it isn't able to acquire the necessary monitors to enter a synchronized block. A thread waits for other threads to reliquish the monitor. A thread in this state isnt doing any work 

SLEEPING  / WAITING ON CONDITION:
A thread sleeps when it calls Thread.sleep(long). As the name suggests the thread isnt doing anything in this state either

No comments:

Post a Comment