Title | Synchronization in Java |
---|---|
Author | Sakshi Bhalothia |
Course | Java Programming |
Institution | Banasthali Vidyapith |
Pages | 11 |
File Size | 93.6 KB |
File Type | |
Total Downloads | 148 |
Total Views | 270 |
Synchronizati on i n Java Synchronization in java is the capability to control the access of multiple threads to any shared resource. Java Synchronization is better option where we want to allow only one thread to access the shared resource.Why use SynchronizationThe synchronization is mainly used...
Sy nc hr oni z at i oni nJ av a
Synchronization in java is the capability to control the access of multiple threads to any shared resource.
Java Synchronization is better option where we want to allow only one thread to access the shared resource.
Whyus eSy nc hr oni z at i on The synchronization is mainly used to 1. To prevent thread interference. 2. To prevent consistency problem.
Thr eadSy nc hr oni z at i on There are two types of thread synchronization mutual exclusive and inter-thread communication. 1. Mutual Exclusive 1. Synchronized method. 2. Synchronized block. 2. Co-operation (Inter-thread communication in java)
Mut ual Ex c l us i v e Mutual Exclusive helps keep threads from interfering with one another while sharing data. This can be done by three ways in java: 1. by synchronized method 2. by synchronized block
1
Conc eptofLocki nJav a Synchronization is built around an internal entity known as the lock or monitor. Every object has an lock associated with it. By convention, a thread that needs consistent access to an object's fields has to acquire the object's lock before accessing them, and then release the lock when it's done with them. Class Table{
void printTable(int n){//method not synchronized for(int i=1;i...