Object Oriented Programming: Unit III: Exception Handling and Multithreading

Java Thread Model

methods with Purpose

Thread is life cycle specifies how a thread gets processed in the Java program. By executing various methods. Following figure represents how a particular thread can be in one of the state at any time.

Java Thread Model

Thread is life cycle specifies how a thread gets processed in the Java program. By executing various methods. Following figure represents how a particular thread can be in one of the state at any time.

New state

• When a thread starts its life cycle it enters in the new state or a create state.

Runnable state

• This is a state in which a thread starts executing.

• Waiting state

• Sometimes one thread has to undergo in waiting state because another thread starts executing.

Timed waiting state

• There is a provision to keep a particular threading waiting for some time interval. This allows to execute high prioritized threads first. After the timing gets over, the thread in waiting state enters in runnable state.

Blocked state

• When a particular thread issues an Input/Output request then operating system sends it in blocked state until the I/O operation gets completed. After the I/O completion the thread is sent back to the runnable state.

Terminated state

After successful completion of the execution the thread in runnable state enters the terminated state.

Review Questions

1.What is thread? Explain its state and methods.

2.Write about various threads states in Java.

3.Explain: States of a thread with a neat diagram.

4.Define threads. Describe in detail about thread life cycle.

5. Explain in detail the different states of a thread.

Object Oriented Programming: Unit III: Exception Handling and Multithreading : Tag: : methods with Purpose - Java Thread Model