SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
TOPIC:
Multithreading
What is Multithreading?
Multithreading in java is a process of
executing multiple threads simultaneously.
It is a conceptual programing paradigm
where a program is divided into two or
more subprograms which can be
implemented at the same time.
Life Cycle Of Thread
Life Cycle Of Thread(in details)
Newborn : When we create a new Thread
object using new operator , thread state is New
Thread .At this point thread is not alive and it’s
a state internal to java program.
Runnable: When we call start() function on
Thread object ,it’s state is changed to Runnable
. The control is given to Thread scheduler to
finish it’s execution.
Running: When thread is executing, it’s state is
changed to Running. A thread can change state to
Runnable, Dead or Blocked from running state
depends on time slicing, thread completion run()
method or waiting for some resources.
Blocked /Waiting: The programmer can make a
running thread to become inactive temporarily
for some period. In this period, the thread is
said to be in blocked state.
Dead : When the execution of run() method is
over, as the job it is meant is done, it is brought
to dead state.
Some Thread Method
Start(): Creates a new thread and make it runnable.
run(): It is used to perform action for a thread.
yield(): causes the currently executing thread object to
temporarily pause and allow other threads to execute.
suspend(): is used to suspend the thread
resume(): is used to resume the suspended thread
Sleep():A thread to sleep for specified time period using
the method sleep.
stop(): is used to stop the thread.
Wait():it is use a thread inactive foe some time.
notify():it use to resume the waited thread.
Example
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();
}
}
How to create thread
There are two ways to create a thread:
1.By extending Thread class
2.By implementing Runnable interface.
Thread Class: Thread class provide constructors and
methods to create and perform operations on a thread.
Thread class extends Object class and implements
Runnable interface. Example:
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();
} }
Runnable Interface: The Runnable interface should be
implemented by any class whose instances are
intended to be executed by a thread. Runnable
interface have only one method named run().
Example:
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();
} }
Priority of a Thread
Each thread have a priority. Priorities are
represented by a number between 1 and 10. In most
cases, thread scheduler schedules the threads
according to their priority (known as preemptive
scheduling).
Type of priority:
1.public static int MIN_PRIORITY(1)
2.public static int NORM_PRIORITY(5)
3.public static int MAX_PRIORITY(10)
Priority of a Thread(Example)
class TestMultiPriority1 extends Thread{
public void run(){
System.out.println("running thread name is:"+Thread.currentThread().getName());
System.out.println("running thread priority is:"+Thread.currentThread().getPriority());
}
public static void main(String args[]){
TestMultiPriority1 m1=new TestMultiPriority1();
TestMultiPriority1 m2=new TestMultiPriority1();
m1.setPriority(Thread.MIN_PRIORITY);
m2.setPriority(Thread.MAX_PRIORITY);
m1.start();
m2.start();
} }
Advantages of Java Multithreading
1) It doesn't block the user because threads
are independent and you can perform
multiple operations at the same time.
2) You can perform many operations together,
so it saves time.
3) Threads are independent, so it doesn't
affect other threads if an exception occurs in
a single thread.
Multithreading in java

More Related Content

What's hot (20)

ODP
Multithreading In Java
parag
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PDF
Generics
Ravi_Kant_Sahu
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Arrays in Java
Abhilash Nair
 
PDF
Java Thread Synchronization
Benj Del Mundo
 
PDF
Arrays in Java
Naz Abdalla
 
PDF
Threads concept in java
Muthukumaran Subramanian
 
PPTX
Polymorphism in java
Elizabeth alexander
 
ODP
OOP java
xball977
 
PPT
Abstract class in java
Lovely Professional University
 
PPS
Wrapper class
kamal kotecha
 
PPTX
Constructor in java
Hitesh Kumar
 
PPT
Basic of Multithreading in JAva
suraj pandey
 
PPTX
Interfaces in java
Abishek Purushothaman
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PPTX
Multithreading in java
junnubabu
 
PPT
Inheritance in java
Lovely Professional University
 
PPTX
Method overloading
Lovely Professional University
 
Multithreading In Java
parag
 
Java constructors
QUONTRASOLUTIONS
 
Java exception handling
BHUVIJAYAVELU
 
Generics
Ravi_Kant_Sahu
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Arrays in Java
Abhilash Nair
 
Java Thread Synchronization
Benj Del Mundo
 
Arrays in Java
Naz Abdalla
 
Threads concept in java
Muthukumaran Subramanian
 
Polymorphism in java
Elizabeth alexander
 
OOP java
xball977
 
Abstract class in java
Lovely Professional University
 
Wrapper class
kamal kotecha
 
Constructor in java
Hitesh Kumar
 
Basic of Multithreading in JAva
suraj pandey
 
Interfaces in java
Abishek Purushothaman
 
Access modifiers in java
Madishetty Prathibha
 
Multithreading in java
junnubabu
 
Inheritance in java
Lovely Professional University
 
Method overloading
Lovely Professional University
 

Similar to Multithreading in java (20)

PPTX
Threads in Java
HarshaDokula
 
PPTX
Multithreading in java
Kavitha713564
 
PPTX
Multithreading in java
Kavitha713564
 
PPTX
Concept of Java Multithreading-Partially.pptx
SahilKumar542
 
PPTX
Internet Programming with Java
kavitha muneeshwaran
 
PPTX
Multithreading programming in java
Elizabeth alexander
 
PDF
JAVA 3.2.pdfhdfkjhdfvbjdbjfhjdfhdjhfjdfdjfhdjhjd
KusumitaSahoo1
 
PPT
multhi threading concept in oops through java
Parameshwar Maddela
 
PPTX
multithreading to be used in java with good programs.pptx
PriyadharshiniG41
 
PPTX
Chap3 multi threaded programming
raksharao
 
PPTX
U4 JAVA.pptx
madan r
 
PPTX
multithreading,thread and processinjava-210302183809.pptx
ArunPatrick2
 
PPT
Session 7_MULTITHREADING in java example.ppt
TabassumMaktum
 
PPTX
Multi-Threading in Java power point presenetation
AshokRachapalli1
 
PPTX
multithreading.pptx
Sravanibitragunta
 
PPTX
Thread priorities in java
Ducat India
 
PPTX
MSBTE Computer Engineering JPR java. multi. threading.pptx
kunalgaikwad1705
 
PPT
multithreading, creating a thread and life cycle in java.ppt
shikhaverma566116
 
PDF
Unit-3 MULTITHREADING-2.pdf
GouthamSoma1
 
Threads in Java
HarshaDokula
 
Multithreading in java
Kavitha713564
 
Multithreading in java
Kavitha713564
 
Concept of Java Multithreading-Partially.pptx
SahilKumar542
 
Internet Programming with Java
kavitha muneeshwaran
 
Multithreading programming in java
Elizabeth alexander
 
JAVA 3.2.pdfhdfkjhdfvbjdbjfhjdfhdjhfjdfdjfhdjhjd
KusumitaSahoo1
 
multhi threading concept in oops through java
Parameshwar Maddela
 
multithreading to be used in java with good programs.pptx
PriyadharshiniG41
 
Chap3 multi threaded programming
raksharao
 
U4 JAVA.pptx
madan r
 
multithreading,thread and processinjava-210302183809.pptx
ArunPatrick2
 
Session 7_MULTITHREADING in java example.ppt
TabassumMaktum
 
Multi-Threading in Java power point presenetation
AshokRachapalli1
 
multithreading.pptx
Sravanibitragunta
 
Thread priorities in java
Ducat India
 
MSBTE Computer Engineering JPR java. multi. threading.pptx
kunalgaikwad1705
 
multithreading, creating a thread and life cycle in java.ppt
shikhaverma566116
 
Unit-3 MULTITHREADING-2.pdf
GouthamSoma1
 
Ad

More from Arafat Hossan (20)

PPTX
Data Dictionary in System Analysis and Design
Arafat Hossan
 
PPTX
Digital Data to Digital Signal Conversion
Arafat Hossan
 
PPTX
Error and Exception Handling in PHP
Arafat Hossan
 
PPTX
Bus Interface Unit(BIU) of 8086 Microprocessor
Arafat Hossan
 
PPTX
Assembly language
Arafat Hossan
 
PPTX
Web frameworks
Arafat Hossan
 
PPTX
Cpu scheduling
Arafat Hossan
 
PPTX
Semaphore
Arafat Hossan
 
PPTX
Deadlock
Arafat Hossan
 
PPTX
Data model
Arafat Hossan
 
PPT
Mapping cardinalities
Arafat Hossan
 
PPTX
Sql in dbms
Arafat Hossan
 
PPTX
Relational algebra in DBMS
Arafat Hossan
 
PPTX
Divisible rules
Arafat Hossan
 
PPTX
Processes in Operating System
Arafat Hossan
 
PPTX
All pair shortest path
Arafat Hossan
 
PPT
Asymptotic notation
Arafat Hossan
 
PPTX
Merge sort
Arafat Hossan
 
PPTX
Job sequencing with deadline
Arafat Hossan
 
PPTX
Multithreading in java
Arafat Hossan
 
Data Dictionary in System Analysis and Design
Arafat Hossan
 
Digital Data to Digital Signal Conversion
Arafat Hossan
 
Error and Exception Handling in PHP
Arafat Hossan
 
Bus Interface Unit(BIU) of 8086 Microprocessor
Arafat Hossan
 
Assembly language
Arafat Hossan
 
Web frameworks
Arafat Hossan
 
Cpu scheduling
Arafat Hossan
 
Semaphore
Arafat Hossan
 
Deadlock
Arafat Hossan
 
Data model
Arafat Hossan
 
Mapping cardinalities
Arafat Hossan
 
Sql in dbms
Arafat Hossan
 
Relational algebra in DBMS
Arafat Hossan
 
Divisible rules
Arafat Hossan
 
Processes in Operating System
Arafat Hossan
 
All pair shortest path
Arafat Hossan
 
Asymptotic notation
Arafat Hossan
 
Merge sort
Arafat Hossan
 
Job sequencing with deadline
Arafat Hossan
 
Multithreading in java
Arafat Hossan
 
Ad

Recently uploaded (20)

PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Day2 B2 Best.pptx
helenjenefa1
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 

Multithreading in java

  • 2. What is Multithreading? Multithreading in java is a process of executing multiple threads simultaneously. It is a conceptual programing paradigm where a program is divided into two or more subprograms which can be implemented at the same time.
  • 3. Life Cycle Of Thread
  • 4. Life Cycle Of Thread(in details) Newborn : When we create a new Thread object using new operator , thread state is New Thread .At this point thread is not alive and it’s a state internal to java program. Runnable: When we call start() function on Thread object ,it’s state is changed to Runnable . The control is given to Thread scheduler to finish it’s execution.
  • 5. Running: When thread is executing, it’s state is changed to Running. A thread can change state to Runnable, Dead or Blocked from running state depends on time slicing, thread completion run() method or waiting for some resources.
  • 6. Blocked /Waiting: The programmer can make a running thread to become inactive temporarily for some period. In this period, the thread is said to be in blocked state. Dead : When the execution of run() method is over, as the job it is meant is done, it is brought to dead state.
  • 7. Some Thread Method Start(): Creates a new thread and make it runnable. run(): It is used to perform action for a thread. yield(): causes the currently executing thread object to temporarily pause and allow other threads to execute. suspend(): is used to suspend the thread resume(): is used to resume the suspended thread Sleep():A thread to sleep for specified time period using the method sleep. stop(): is used to stop the thread. Wait():it is use a thread inactive foe some time. notify():it use to resume the waited thread.
  • 8. Example 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(); } }
  • 9. How to create thread There are two ways to create a thread: 1.By extending Thread class 2.By implementing Runnable interface.
  • 10. Thread Class: Thread class provide constructors and methods to create and perform operations on a thread. Thread class extends Object class and implements Runnable interface. Example: 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(); } }
  • 11. Runnable Interface: The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. Runnable interface have only one method named run(). Example: 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(); } }
  • 12. Priority of a Thread Each thread have a priority. Priorities are represented by a number between 1 and 10. In most cases, thread scheduler schedules the threads according to their priority (known as preemptive scheduling). Type of priority: 1.public static int MIN_PRIORITY(1) 2.public static int NORM_PRIORITY(5) 3.public static int MAX_PRIORITY(10)
  • 13. Priority of a Thread(Example) class TestMultiPriority1 extends Thread{ public void run(){ System.out.println("running thread name is:"+Thread.currentThread().getName()); System.out.println("running thread priority is:"+Thread.currentThread().getPriority()); } public static void main(String args[]){ TestMultiPriority1 m1=new TestMultiPriority1(); TestMultiPriority1 m2=new TestMultiPriority1(); m1.setPriority(Thread.MIN_PRIORITY); m2.setPriority(Thread.MAX_PRIORITY); m1.start(); m2.start(); } }
  • 14. Advantages of Java Multithreading 1) It doesn't block the user because threads are independent and you can perform multiple operations at the same time. 2) You can perform many operations together, so it saves time. 3) Threads are independent, so it doesn't affect other threads if an exception occurs in a single thread.