0% found this document useful (0 votes)
12 views4 pages

Threading

Multi-threading allows multiple sections of the same application to execute simultaneously, with each section referred to as a thread. The life cycle of a thread includes stages such as Start, Ready, Running, Waiting, and Dead. Threads can be created using the Thread class or the Runnable interface, and they can be paused using the sleep method.

Uploaded by

Pace Infotech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Threading

Multi-threading allows multiple sections of the same application to execute simultaneously, with each section referred to as a thread. The life cycle of a thread includes stages such as Start, Ready, Running, Waiting, and Dead. Threads can be created using the Thread class or the Runnable interface, and they can be paused using the sleep method.

Uploaded by

Pace Infotech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

Multi-Threading :

Multi-tasking is the process of executing the multiple


applications at the
same time . e.g. Windows 98 , etc ... supports multi-tasking .
For example , we are running the Wordpad and winamp at the
same time.

Multi-threading refers to executing the multiple sections of the


same application
at the same time.
The section of the same application is known as the Thread .

The Life Cycle of the Thread is ,

Life Cycle of the Thread includes the following stages ,

i. Start
ii. Ready
iii Running
iv Waiting
v Dead

i. Start : When the thread is created , it automatically


entered in this stage.

ii. Ready : When the thread gathered all the resources


required for its
execution , then it enters in the Ready state , that
is, it is now
waiting for the cpu to execute it .

iii Running : When the thread is executed by the cpu , then it


enters in the running state.

iv Waiting : When the thread is dealing or interacting with the


input or output
device.The thread enters in the waiting state .

v Dead : When the thread finishes its e


xecution , it enters in the Dea
d state.

To create the Thread , there are two different ways ,

i. Using the Thread class

ii. Using the Runnable Interface

i. Using the Thread class .


----------------------------

To create the Thread we have to first create the class on the


basis of the
Thread class , which is defined in the package java.lang

The general form is,


class ThreadName extends Thread
{
void run()
{
//body of the function
}
}

Now , we will create the object of the ThreadName class .

ThreadName objectname=new ThreadName();

Now , to start the thread executing , we will use ,

objectname.start();

The main purpose of thread is used to execute a particular


section of code
after a certain duration of time .

objectname.sleep(nmilliseconds)

e.g.
ob.sleep(1000);

You might also like