SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
SYNCHRONIZATION IN
MULTITHREADING
WHAT IS
SYNCHRONIZATION
SYNCHRONIZATION IN JAVA IS THE
CAPABILITY TO CONTROL THE ACCESS OF
MULTIPLE THREADS TO ANY SHARED
RESOURCE.
IN MULTITHREAD ENVIRONMENT IT
ENSURES THAT THE SHARED RESOURCE
CAN BE ACCESSED BY ONLY ONE THREAD
AT A TIME.
WHY SYNCHRONIZATION
01 Avoid Race Condition
03 Thread Safety
02 Mutual Exclusion
04 Ordering
05 Consistency 06 Efficiency
Types of Synchronization
There are two types of synchronization
1.Process Synchronization
2.Thread Synchronization
1.PROCESS SYNCHRONIZATION
Process synchronization refers to the coordination and control of multiple
processes in a multitasking or multi-processing environment.
In a multitasking operating system, multiple processes run concurrently,
and they may need to access shared resources or communicate with each
other.
2.THREAD
SYNCHRONIZATION
Thread synchronization in Java is a technique used to control access to
shared resources by multiple threads to prevent race conditions and
ensure data consistency. It ensures that only one thread can access a
critical section of code or a shared resource at a time.
MUTUAL EXCLUSIVE
Mutual Exclusive helps keep threads from interfering with one another
while sharing data. It can be achieved by using the following three
ways:
By Using Synchronized Method
1.
2.By Using Synchronized Block
3.By Using Static Synchronization
1.BY USING SYNCHRONIZED METHOD
synchronized methods is a way to control concurrent access
to methods or blocks of code in Java. When a method is
declared as synchronized, only one thread can execute that
method at a time for a given instance of the class.
WITHOUT SYNCHRONIZED METHOD
OUTPUT
SYNCHRONIZED METHOD
OUTPUT
In Java, a synchronized block is a block of code
that is marked as synchronized, allowing only one
thread to execute the block at a time. This is
useful when multiple threads need to access
shared resources or critical sections of code
concurrently, and you want to ensure that only
one thread can access the critical section at any
given time to prevent race conditions and
maintain data consistency.
2.By Using
Synchronized Block
SYNCHRONIZED BLOCK
OUTPUT
3.BY USING STATIC SYNCHRONIZED
Static synchronization, also known as class-level
synchronization, refers to the synchronization of static
methods or code blocks in Java. When a method or code
block is declared as synchronized and static, it means that
the synchronization is applied at the class level rather than
at the instance level. This ensures that only one thread can
execute the synchronized static method or code block
across all instances of the class at any given time.
WITHOUT STATIC
SYNCHRONIZATION
WITH STATIC
SYNCHRONIZATION
OUTPUT
WITHOUT STATIC
SYNCHRONIZATION
OUTPUT
Synchronization
Class Level Lock
SUNCHRONIZATION WITH LOCKS
Object Level
Lock
Class Level Lock
For the shared resource, each object, only
one object can have access at a time, other
objects of the shared resource will wait.
Object Level Lock
An object level lock, on the other hand, involves
synchronizing access to individual objects rather than
entire classes. Each object instance has its own lock,
and threads must acquire the lock associated with a
specific object before accessing synchronized
methods or code blocks of that object.
APPLICATIONS
01 Operating System
03 Security and
Encryption
02 Distributed Systems
04 Manufacturing and
Robotics
05 Concurrency Control
in Web Servers
06 Supply Chain
Management
Java Presentation On Synchronization in Multithreading

Contenu connexe

Similaire à Java Presentation On Synchronization in Multithreading

Process synchronization
Process synchronizationProcess synchronization
Process synchronizationlodhran-hayat
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in JavaM. Raihan
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”IOSR Journals
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
Concurrency Utilities Overview
Concurrency Utilities OverviewConcurrency Utilities Overview
Concurrency Utilities Overviewwhite paper
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Multiprocessing.pptx
Multiprocessing.pptxMultiprocessing.pptx
Multiprocessing.pptxMaheshGour5
 
Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Abu Bakr Ramadan
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick GuideAnton Shchastnyi
 

Similaire à Java Presentation On Synchronization in Multithreading (20)

Interface
InterfaceInterface
Interface
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 
The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Multithreading.
Multithreading.Multithreading.
Multithreading.
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Concurrency Utilities Overview
Concurrency Utilities OverviewConcurrency Utilities Overview
Concurrency Utilities Overview
 
Pocket java
Pocket javaPocket java
Pocket java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Process coordination
Process coordinationProcess coordination
Process coordination
 
Class loaders
Class loadersClass loaders
Class loaders
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Multiprocessing.pptx
Multiprocessing.pptxMultiprocessing.pptx
Multiprocessing.pptx
 
Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
Java mcq
Java mcqJava mcq
Java mcq
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick Guide
 

Dernier

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Dernier (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

Java Presentation On Synchronization in Multithreading

  • 2. WHAT IS SYNCHRONIZATION SYNCHRONIZATION IN JAVA IS THE CAPABILITY TO CONTROL THE ACCESS OF MULTIPLE THREADS TO ANY SHARED RESOURCE. IN MULTITHREAD ENVIRONMENT IT ENSURES THAT THE SHARED RESOURCE CAN BE ACCESSED BY ONLY ONE THREAD AT A TIME.
  • 3. WHY SYNCHRONIZATION 01 Avoid Race Condition 03 Thread Safety 02 Mutual Exclusion 04 Ordering 05 Consistency 06 Efficiency
  • 4. Types of Synchronization There are two types of synchronization 1.Process Synchronization 2.Thread Synchronization
  • 5. 1.PROCESS SYNCHRONIZATION Process synchronization refers to the coordination and control of multiple processes in a multitasking or multi-processing environment. In a multitasking operating system, multiple processes run concurrently, and they may need to access shared resources or communicate with each other.
  • 6. 2.THREAD SYNCHRONIZATION Thread synchronization in Java is a technique used to control access to shared resources by multiple threads to prevent race conditions and ensure data consistency. It ensures that only one thread can access a critical section of code or a shared resource at a time.
  • 7. MUTUAL EXCLUSIVE Mutual Exclusive helps keep threads from interfering with one another while sharing data. It can be achieved by using the following three ways: By Using Synchronized Method 1. 2.By Using Synchronized Block 3.By Using Static Synchronization
  • 8. 1.BY USING SYNCHRONIZED METHOD synchronized methods is a way to control concurrent access to methods or blocks of code in Java. When a method is declared as synchronized, only one thread can execute that method at a time for a given instance of the class.
  • 13. In Java, a synchronized block is a block of code that is marked as synchronized, allowing only one thread to execute the block at a time. This is useful when multiple threads need to access shared resources or critical sections of code concurrently, and you want to ensure that only one thread can access the critical section at any given time to prevent race conditions and maintain data consistency. 2.By Using Synchronized Block
  • 16. 3.BY USING STATIC SYNCHRONIZED Static synchronization, also known as class-level synchronization, refers to the synchronization of static methods or code blocks in Java. When a method or code block is declared as synchronized and static, it means that the synchronization is applied at the class level rather than at the instance level. This ensures that only one thread can execute the synchronized static method or code block across all instances of the class at any given time.
  • 22. Synchronization Class Level Lock SUNCHRONIZATION WITH LOCKS Object Level Lock
  • 23. Class Level Lock For the shared resource, each object, only one object can have access at a time, other objects of the shared resource will wait.
  • 24. Object Level Lock An object level lock, on the other hand, involves synchronizing access to individual objects rather than entire classes. Each object instance has its own lock, and threads must acquire the lock associated with a specific object before accessing synchronized methods or code blocks of that object.
  • 25. APPLICATIONS 01 Operating System 03 Security and Encryption 02 Distributed Systems 04 Manufacturing and Robotics 05 Concurrency Control in Web Servers 06 Supply Chain Management