SlideShare a Scribd company logo
Multithreading
in
Java
1rkm
Multithreading in Java
You will Learn :
 Multiprogramming
 Multitasking
 Multithreading & Thread
 Diff between Multiprogramming & Multithreading
 Practical use of Multithreading
 Advantages
 Implementation of Multithreading in Java
 Built-in Library for Multithreading in Java
 Important methods to implement Multithreading in Java
 Program of Multithreading in Eclipse
2rkm
Multiprogramming
Multiprogramming is the ability of an operating system to execute
multiple programs at the same time on single processor machine.
If the currently executing process performs i/o operation or
waiting for i/o then the Operating System may interrupt that
process and gives the control to other process residing in main
memory.
Process 1
Process 2
i/o of P1
3rkm
The process of having a computer perform multiple tasks
simultaneously.
For example : Listening of music in background while browsing
internet or typing in MS-Word in foreground.
Multitasking
4rkm
Multithreading
It is the ability of a CPU which execute multiple
thread concurrently, supported by the operating system
Thread : A Thread is the smallest
sequence of programmed
instructions that can be managed
independently.
Threads are independent because
they all have separate path of
execution that’s the reason if an
exception occurs in one thread, it
doesn’t affect the execution of
other threads.
5rkm
Objective of Multithreading:
•To increase utilization of a single core by using Thread-level parallelism, as well
as Instruction-level parallelism.
Difference between Process and Thread :
•Process means any program is in execution while thread is a segment of the process.
•Every process uses separate memory while all the threads use shared memory.
Multithreading
6rkm
While you are typing on Ms-Word spell check checking spelling
and informed to user about the spelling mistake. Spell check
working as a Thread.
Practical use of Thread
7rkm
User
•When you insert ATM card into ATM Machine it start a new thread to
perform your request. There are multiple account holders on the same
server requesting the server simultaneously. Server software create a
new thread for every user.
•Railway reservation system where multiple users accessing the same
server.
Practical use of Thread
Server
8rkm
•When you request to Amazon server from your mobile
through Amazon App, that request become a thread and
your Mobile Application doing another task when request
is forward in the form of thread.
Practical use of Thread
9rkm
In multimedia games you can use multiple objects like
human, gun etc. These objects are nothing but the
threads.
Practical use of Thread
10rkm
Advantages of Multithreading
•Threads are independent so users are not blocked and we
can perform multiple operations at times.
•The other threads won't get affected if one thread meets an
exception.
•Multiple threads don't allocate separate memory area, hence they
save memory.
•In Multithreading context switching between threads takes less
time.
11rkm
Implementation of Threads in Java
Thread Life Cycle in Java
12rkm
•New: The thread is created using class "Thread class". It remains in this
state till the program starts the thread. It is also known as born thread.
•Runnable: The instance of the thread is invoked with a start method.
The thread control is given to scheduler to finish the execution. It
depends on the scheduler, whether to run the thread.
•Running: The scheduler selects one thread from the thread pool, and it
starts executing in the application.
•Waiting: This is the state when a thread has to wait. As there multiple
threads are running in the application, there is a need for synchronization
between threads. Hence, one thread has to wait, till the other thread gets
executed. Therefore, this state is referred as waiting state.
•Dead: This is the state when the thread is terminated. The thread is in
running state and as soon as it completed processing it is in "dead
state".
Thread Life Cycle in Java (Stages)
13rkm
Built-in Library of Java for Thread
Built-in Class : Thread
Built-in Interface : Runnable
Package for both : java.lang
(java.lang is default package of Java so it
is no need to import explicitly. )
14rkm
Important Methods of Java Thread Class
void start() : It use to start the execution of thread. It call the run()
method defined to do some action in thread.
void run() : It used to define an action for thread.
static void sleep() : It sleeps a thread for specified time or a thread enter in
wait state for a specified time.
void stop(): It used to stop a thread.
void destroy() : It used to destroy the thread.
void suspend() : It used to suspend the thread.
void resume() : It resume the suspended thread.
static yield(): It pause the currently executing thread and allow other
thread to execute temporarily.
15rkm
Practical Program on Eclipse
16rkm

More Related Content

PPTX
Multi threading
PPT
Chap2 2 1
PPTX
PPTX
Multithreading
PPTX
Java Multi Thead Programming
PPT
MULTITHREADING CONCEPT
PPTX
Multithreading
PDF
Multithreading
Multi threading
Chap2 2 1
Multithreading
Java Multi Thead Programming
MULTITHREADING CONCEPT
Multithreading
Multithreading

What's hot (19)

PPT
Java Threads
PPTX
PPTX
Threads .ppt
PPTX
Multithreading in java
PDF
Java thread life cycle
PPTX
Multi-threaded Programming in JAVA
PPT
Java And Multithreading
PPTX
Multithreading in java
PPTX
Threads and multi threading
PDF
Java threads
PPTX
Networking threads
PPTX
Thread (Operating System)
PPTX
Threading in C#
PDF
Threads concept in java
PPTX
Multi-Threading
PPT
Java Multithreading
PPT
Multithreading
PPTX
Threads (operating System)
PPTX
Java Thread & Multithreading
Java Threads
Threads .ppt
Multithreading in java
Java thread life cycle
Multi-threaded Programming in JAVA
Java And Multithreading
Multithreading in java
Threads and multi threading
Java threads
Networking threads
Thread (Operating System)
Threading in C#
Threads concept in java
Multi-Threading
Java Multithreading
Multithreading
Threads (operating System)
Java Thread & Multithreading
Ad

Similar to Introduction to Multithreading in Java (20)

PPTX
Internet Programming with Java
PPT
multhi threading concept in oops through java
PPTX
multithreading,thread and processinjava-210302183809.pptx
PPTX
U4 JAVA.pptx
PPTX
Multithreading in java
PPT
web programming-Multithreading concept in Java.ppt
PPTX
Threading.pptx
PPTX
OOPS object oriented programming UNIT-4.pptx
PPTX
Threads in Java
PDF
Unit-3 MULTITHREADING-2.pdf
PPTX
Multithreading in Java Object Oriented Programming language
DOCX
Module - 5 merged.docx notes about engineering subjects java
PPTX
Multi-Threading in Java power point presenetation
PDF
java programming concept multithreading multitasking.pdf
PDF
Multi t hreading_14_10
PPTX
Object-Oriented-Prog_MultiThreading.pptx
PPT
JAVA MULTITHREDED PROGRAMMING - LECTURES
PPTX
Multithreading.pptx
PPTX
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
Internet Programming with Java
multhi threading concept in oops through java
multithreading,thread and processinjava-210302183809.pptx
U4 JAVA.pptx
Multithreading in java
web programming-Multithreading concept in Java.ppt
Threading.pptx
OOPS object oriented programming UNIT-4.pptx
Threads in Java
Unit-3 MULTITHREADING-2.pdf
Multithreading in Java Object Oriented Programming language
Module - 5 merged.docx notes about engineering subjects java
Multi-Threading in Java power point presenetation
java programming concept multithreading multitasking.pdf
Multi t hreading_14_10
Object-Oriented-Prog_MultiThreading.pptx
JAVA MULTITHREDED PROGRAMMING - LECTURES
Multithreading.pptx
07. Parbdhdjdjdjsjsjdjjdjdjjkdkkdkdkt.pptx
Ad

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
English Language Teaching from Post-.pdf
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Introduction and Scope of Bichemistry.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
English Language Teaching from Post-.pdf
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Open folder Downloads.pdf yes yes ges yes
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
human mycosis Human fungal infections are called human mycosis..pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
How to Manage Starshipit in Odoo 18 - Odoo Slides
O5-L3 Freight Transport Ops (International) V1.pdf
Module 3: Health Systems Tutorial Slides S2 2025
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Introduction and Scope of Bichemistry.pptx

Introduction to Multithreading in Java

  • 2. Multithreading in Java You will Learn :  Multiprogramming  Multitasking  Multithreading & Thread  Diff between Multiprogramming & Multithreading  Practical use of Multithreading  Advantages  Implementation of Multithreading in Java  Built-in Library for Multithreading in Java  Important methods to implement Multithreading in Java  Program of Multithreading in Eclipse 2rkm
  • 3. Multiprogramming Multiprogramming is the ability of an operating system to execute multiple programs at the same time on single processor machine. If the currently executing process performs i/o operation or waiting for i/o then the Operating System may interrupt that process and gives the control to other process residing in main memory. Process 1 Process 2 i/o of P1 3rkm
  • 4. The process of having a computer perform multiple tasks simultaneously. For example : Listening of music in background while browsing internet or typing in MS-Word in foreground. Multitasking 4rkm
  • 5. Multithreading It is the ability of a CPU which execute multiple thread concurrently, supported by the operating system Thread : A Thread is the smallest sequence of programmed instructions that can be managed independently. Threads are independent because they all have separate path of execution that’s the reason if an exception occurs in one thread, it doesn’t affect the execution of other threads. 5rkm
  • 6. Objective of Multithreading: •To increase utilization of a single core by using Thread-level parallelism, as well as Instruction-level parallelism. Difference between Process and Thread : •Process means any program is in execution while thread is a segment of the process. •Every process uses separate memory while all the threads use shared memory. Multithreading 6rkm
  • 7. While you are typing on Ms-Word spell check checking spelling and informed to user about the spelling mistake. Spell check working as a Thread. Practical use of Thread 7rkm
  • 8. User •When you insert ATM card into ATM Machine it start a new thread to perform your request. There are multiple account holders on the same server requesting the server simultaneously. Server software create a new thread for every user. •Railway reservation system where multiple users accessing the same server. Practical use of Thread Server 8rkm
  • 9. •When you request to Amazon server from your mobile through Amazon App, that request become a thread and your Mobile Application doing another task when request is forward in the form of thread. Practical use of Thread 9rkm
  • 10. In multimedia games you can use multiple objects like human, gun etc. These objects are nothing but the threads. Practical use of Thread 10rkm
  • 11. Advantages of Multithreading •Threads are independent so users are not blocked and we can perform multiple operations at times. •The other threads won't get affected if one thread meets an exception. •Multiple threads don't allocate separate memory area, hence they save memory. •In Multithreading context switching between threads takes less time. 11rkm
  • 12. Implementation of Threads in Java Thread Life Cycle in Java 12rkm
  • 13. •New: The thread is created using class "Thread class". It remains in this state till the program starts the thread. It is also known as born thread. •Runnable: The instance of the thread is invoked with a start method. The thread control is given to scheduler to finish the execution. It depends on the scheduler, whether to run the thread. •Running: The scheduler selects one thread from the thread pool, and it starts executing in the application. •Waiting: This is the state when a thread has to wait. As there multiple threads are running in the application, there is a need for synchronization between threads. Hence, one thread has to wait, till the other thread gets executed. Therefore, this state is referred as waiting state. •Dead: This is the state when the thread is terminated. The thread is in running state and as soon as it completed processing it is in "dead state". Thread Life Cycle in Java (Stages) 13rkm
  • 14. Built-in Library of Java for Thread Built-in Class : Thread Built-in Interface : Runnable Package for both : java.lang (java.lang is default package of Java so it is no need to import explicitly. ) 14rkm
  • 15. Important Methods of Java Thread Class void start() : It use to start the execution of thread. It call the run() method defined to do some action in thread. void run() : It used to define an action for thread. static void sleep() : It sleeps a thread for specified time or a thread enter in wait state for a specified time. void stop(): It used to stop a thread. void destroy() : It used to destroy the thread. void suspend() : It used to suspend the thread. void resume() : It resume the suspended thread. static yield(): It pause the currently executing thread and allow other thread to execute temporarily. 15rkm
  • 16. Practical Program on Eclipse 16rkm