Home           J2EE Concepts           JMS           Java Language           Contact           Back           Next           Bookmark this Page          










Some useful tips related to:
 - health & fitness
 - vehicle care
 - cooking
 - misc household tasks

What is a thread?


When an Operating System needs to execute a program, it creates a process for it. Each process has at least one thread running within it.

A thread is a path of code execution through a program. Each thread may have its own local variables etc.

When we execute a java class, typically two threads are running within JVM. The "main" thread which begins with executing main() method; and Garbage Collector, which is always executing in JVM.


States of a thread!


During its life, a thread moves through various states. These possible states are: new, ready, running, waiting and dead.

New - A thread is in new state immediately after it is created.

Ready - After new state, a thread transitions to Ready state immediately after it is started.

Running - A thread moves to Running state when JVM selects it for execution.

Dead - A thread enters Dead state after its execution has completed. A dead thread can not be restarted again.

Wait - If a thread decides to sleep, it enters Wait state.