SlideShare a Scribd company logo
1 of 20
TOPICINCLUDES:
 Introduction to Thread
 Creation of Thread
 Life cycle of Thread
 DeadLock
INTRODUCTIONTO THREAD
• Thread is the basic unit of Java program
execution.
• Thread: It can be called lightweight process
• Thread requires less resources to create and exists in the
process
• Thread shares the process resources
MULTITHREADING
• Multithreading in java is a process of
executing multiple processes simultaneously
• A program is divided into two or more
subprograms, which can be implemented at
the same time in parallel.
• Multiprocessing and multithreading, both are
used to achieve multitasking.
• Java Multithreading is mostly used in games,
animation etc.
MULTITHREADING
MULTITHREADING
ADVANTAGE:
 It doesn't block the user
 can perform many operations together so it
saves time.
 Threads are independent so it doesn't
affect other threads
CREATINGTHREAD
• Threads are implemented in the form of objects.
• The run() and start() are two inbuilt methods
which helps to thread implementation
• The run() method can be initiating with the help
of start() method.
CREATINGTHREAD
CREATING THREAD
1. By extending Thread class
2. By implementing Runnable
interface
CREATINGTHREAD
1. By Extending Thread class
class Multi extends Thread
{
public void run()
{
System.out.println("thread is running...");
}
public static void main(String args[])
{
Multi t1=new Multi();
t1.start();
}
}
Output: thread is running…
// Extending thread class
// run() method declared
//object initiated
// run() method called through start()
CREATINGTHREAD
2. By implementing Runnable interface
class Multi3 implements Runnable
{
public void run()
{
System.out.println("thread is running...");
}
public static void main(String args[])
{
Multi3 m1=new Multi3();
Thread t1 =new Thread(m1);
t1.start();
} }
// Implementing Runnable interface
// object initiated for class
// object initiated for thread
Output: thread is running…
LIFEcycleof a thread
• During the life time of a thread, there are
many states it can enter.
• They include:
1. Newborn state
2. Runnable state
3. Running state
4. Blocked state
5. Dead state
LIFEcycleof a thread
LIFEcycleof a thread
Newborn State:
 The thread is born and is said to be in newborn
state.
 The thread is not yet scheduled for running.
 At this state, we can do only one of the following:
• Schedule it for running using start() method.
• Kill it using stop() method.
LIFEcycleof a thread
Runnable State:
 The thread is ready for execution
 Waiting for the availability of the processor.
 The thread has joined the queue
LIFEcycleof a thread
Running State:
• Thread is executing
• The processor has given its time to the thread
for its execution.
• The thread runs until it gives up control on its
own or taken over by other threads.
LIFEcycleof a thread
Blocked State:
• A thread is said to be blocked
• It is prevented to entering into the runnable and the
running state.
• This happens when the thread is suspended, sleeping,
or waiting in order to satisfy certain requirements.
• A blocked thread is considered "not runnable" but not
dead and therefore fully qualified to run again.
• This state is achieved when we
Invoke suspend() or sleep() or wait() methods.
LIFEcycleof a thread
Dead State:
• Every thread has a life cycle.
• A running thread ends its life when it has completed
executing its run( ) method. It is a natural death.
• A thread can be killed in born, or in running, or even in
"not runnable" (blocked) condition.
• It is called premature death.
• This state is achieved when we invoke stop() method or
the thread completes it execution.
deadlock
• Deadlock describes a situation where two or
more threads are blocked forever, waiting for
each other.
• when two or more threads are waiting to gain
control on a resource.
For example, assume that the thread A must
access Method1 before it can release Method2, but
the thread B cannot release Method1 until it gets
holds of Method2.
deadlock
THANK YOU

More Related Content

Similar to Multithreading.pptx

Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
Bharat17485
 
Java class 6
Java class 6Java class 6
Java class 6
Edureka!
 
OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptx
Arulmozhivarman8
 
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
nimbalkarvikram966
 

Similar to Multithreading.pptx (20)

Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
 
Chap2 2 1
Chap2 2 1Chap2 2 1
Chap2 2 1
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
 
multithreading.pptx
multithreading.pptxmultithreading.pptx
multithreading.pptx
 
BCA MultiThreading.ppt
BCA MultiThreading.pptBCA MultiThreading.ppt
BCA MultiThreading.ppt
 
Java class 6
Java class 6Java class 6
Java class 6
 
Java Thread
Java ThreadJava Thread
Java Thread
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Threads in Java
Threads in JavaThreads in Java
Threads in Java
 
OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptx
 
Multi threading
Multi threadingMulti threading
Multi threading
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
 
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

More from HemantSharma134028 (7)

b0560b5d-d52d-4bc1-be9c-55aed5fae5e5-151030074028-lva1-app6892.pptx
b0560b5d-d52d-4bc1-be9c-55aed5fae5e5-151030074028-lva1-app6892.pptxb0560b5d-d52d-4bc1-be9c-55aed5fae5e5-151030074028-lva1-app6892.pptx
b0560b5d-d52d-4bc1-be9c-55aed5fae5e5-151030074028-lva1-app6892.pptx
 
Introduction_to_Java.ppt
Introduction_to_Java.pptIntroduction_to_Java.ppt
Introduction_to_Java.ppt
 
HHW OF IT PRESENTATION ON INTERNET SECURITY BY AASTHA SHARMA 10TH KEATS^.pptx
HHW OF IT PRESENTATION ON INTERNET SECURITY BY AASTHA SHARMA 10TH KEATS^.pptxHHW OF IT PRESENTATION ON INTERNET SECURITY BY AASTHA SHARMA 10TH KEATS^.pptx
HHW OF IT PRESENTATION ON INTERNET SECURITY BY AASTHA SHARMA 10TH KEATS^.pptx
 
Lec7!JavaThreads.ppt
Lec7!JavaThreads.pptLec7!JavaThreads.ppt
Lec7!JavaThreads.ppt
 
java basics.pptx
java basics.pptxjava basics.pptx
java basics.pptx
 
Searching.pptx
Searching.pptxSearching.pptx
Searching.pptx
 
Heap Sort (project).ppt
Heap Sort (project).pptHeap Sort (project).ppt
Heap Sort (project).ppt
 

Recently uploaded

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 

Recently uploaded (20)

Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 

Multithreading.pptx

  • 1.
  • 2. TOPICINCLUDES:  Introduction to Thread  Creation of Thread  Life cycle of Thread  DeadLock
  • 3. INTRODUCTIONTO THREAD • Thread is the basic unit of Java program execution. • Thread: It can be called lightweight process • Thread requires less resources to create and exists in the process • Thread shares the process resources
  • 4. MULTITHREADING • Multithreading in java is a process of executing multiple processes simultaneously • A program is divided into two or more subprograms, which can be implemented at the same time in parallel. • Multiprocessing and multithreading, both are used to achieve multitasking. • Java Multithreading is mostly used in games, animation etc.
  • 6. MULTITHREADING ADVANTAGE:  It doesn't block the user  can perform many operations together so it saves time.  Threads are independent so it doesn't affect other threads
  • 7. CREATINGTHREAD • Threads are implemented in the form of objects. • The run() and start() are two inbuilt methods which helps to thread implementation • The run() method can be initiating with the help of start() method.
  • 8. CREATINGTHREAD CREATING THREAD 1. By extending Thread class 2. By implementing Runnable interface
  • 9. CREATINGTHREAD 1. By Extending Thread class class Multi extends Thread { public void run() { System.out.println("thread is running..."); } public static void main(String args[]) { Multi t1=new Multi(); t1.start(); } } Output: thread is running… // Extending thread class // run() method declared //object initiated // run() method called through start()
  • 10. CREATINGTHREAD 2. By implementing Runnable interface class Multi3 implements Runnable { public void run() { System.out.println("thread is running..."); } public static void main(String args[]) { Multi3 m1=new Multi3(); Thread t1 =new Thread(m1); t1.start(); } } // Implementing Runnable interface // object initiated for class // object initiated for thread Output: thread is running…
  • 11. LIFEcycleof a thread • During the life time of a thread, there are many states it can enter. • They include: 1. Newborn state 2. Runnable state 3. Running state 4. Blocked state 5. Dead state
  • 13. LIFEcycleof a thread Newborn State:  The thread is born and is said to be in newborn state.  The thread is not yet scheduled for running.  At this state, we can do only one of the following: • Schedule it for running using start() method. • Kill it using stop() method.
  • 14. LIFEcycleof a thread Runnable State:  The thread is ready for execution  Waiting for the availability of the processor.  The thread has joined the queue
  • 15. LIFEcycleof a thread Running State: • Thread is executing • The processor has given its time to the thread for its execution. • The thread runs until it gives up control on its own or taken over by other threads.
  • 16. LIFEcycleof a thread Blocked State: • A thread is said to be blocked • It is prevented to entering into the runnable and the running state. • This happens when the thread is suspended, sleeping, or waiting in order to satisfy certain requirements. • A blocked thread is considered "not runnable" but not dead and therefore fully qualified to run again. • This state is achieved when we Invoke suspend() or sleep() or wait() methods.
  • 17. LIFEcycleof a thread Dead State: • Every thread has a life cycle. • A running thread ends its life when it has completed executing its run( ) method. It is a natural death. • A thread can be killed in born, or in running, or even in "not runnable" (blocked) condition. • It is called premature death. • This state is achieved when we invoke stop() method or the thread completes it execution.
  • 18. deadlock • Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. • when two or more threads are waiting to gain control on a resource. For example, assume that the thread A must access Method1 before it can release Method2, but the thread B cannot release Method1 until it gets holds of Method2.