{"id":27014,"date":"2023-11-08T09:51:06","date_gmt":"2023-11-08T04:21:06","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/"},"modified":"2025-01-13T14:08:59","modified_gmt":"2025-01-13T08:38:59","slug":"synchronization-in-java","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/","title":{"rendered":"Synchronization in Java"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\"><strong>Introduction<\/strong><\/h2>\n\n\n\n<p>Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-we-use-synchronization\"><strong>Why we use Synchronization<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Synchronization helps in preventing thread interference.<\/li>\n\n\n\n<li>Synchronization helps to prevent concurrency problems.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-synchronization\"><strong>Types of Synchronization<\/strong><\/h2>\n\n\n\n<p>Synchronization is classified into two types<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Process Synchronization<\/li>\n\n\n\n<li>Thread Synchronization<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"process-synchronization\"><strong>Process Synchronization:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The process is nothing but a program under execution. It runs independently isolated from another process. The resources like memory and CPU time, etc. are allocated to the process by the operation System.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"thread-synchronization\"><strong>Thread Synchronization:<\/strong><\/h4>\n\n\n\n<p>Thread synchronization is two types, they are:<\/p>\n\n\n\n<p><strong>1.Mutual Exclusive:<\/strong><\/p>\n\n\n\n<p>A Mutex or Mutual Exclusive helps only one thread to access the shared resources. It won\u2019t allow the accessing of shared resources at a time. It can be achieved in the following ways.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Synchronized Method<\/li>\n\n\n\n<li>Synchronized block<\/li>\n\n\n\n<li>Static Synchronization<\/li>\n<\/ul>\n\n\n\n<p><strong>2. Cooperation (Inter Thread Communication in java)<\/strong><\/p>\n\n\n\n<p>Also check <a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-tutorial-for-beginners\/\" data-type=\"URL\" data-id=\"https:\/\/www.mygreatlearning.com\/blog\/java-tutorial-for-beginners\/\">Java Tutorial for Beginners | An Overview of Java<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"lock-concept-in-java\"><strong>Lock Concept in Java<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Synchronization Mechanism developed by using the synchronized keyword in java language. It is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM). The synchronized keyword is only applicable for methods and blocks, it can\u2019t apply to classes and variables. Synchronized keyword in java creates a block of code is known as a critical section. To enter into the critical section thread needs to obtain the corresponding object\u2019s lock.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"the-problem-without-synchronization\"><strong>The problem without Synchronization:<\/strong><\/h4>\n\n\n\n<p>Below example shows the Powers of the numbers like n<sup>1<\/sup>, n<sup>2<\/sup>, n<sup>3<\/sup>, n<sup>4<\/sup>, n<sup>5<\/sup>&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Power{  \nvoid printPower(int n){\/\/method not synchronized\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n     System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n      Thread.sleep(500);  \n     }catch(Exception e){System.out.println(e);}  \n   }  \n }  \n}  \nclass Thread1 extends Thread{  \nPower p;  \nThread1(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(5);  \n}    \n}  \nclass Thread2 extends Thread{  \nPower p;  \nThread2(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(8);  \n}  \n}  \n  \npublic class Synchronization_Example1{  \npublic static void main(String args&#x5B;]){  \nPower obj = new Power();\/\/only one object  \nThread1 p1=new Thread1(obj);  \nThread2 p2=new Thread2(obj);  \np1.start();  \np2.start();\n}  \n}\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-1:- 8^1 value: 8\nThread-0:- 5^1 value: 5\nThread-1:- 8^2 value: 64\nThread-0:- 5^2 value: 25\nThread-1:- 8^3 value: 512\nThread-0:- 5^3 value: 125\nThread-1:- 8^4 value: 4096\nThread-0:- 5^4 value: 625\nThread-1:- 8^5 value: 32768\nThread-0:- 5^5 value: 3125\n<\/pre><\/div>\n\n\n<p>Here we didn\u2019t use the synchronized keyword so both the threads are executing at a time so in the output, thread-0 is interfering with thread-1, and hence, we are getting inconsistent results.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-synchronized-method\"><strong>Java Synchronized Method<\/strong><\/h2>\n\n\n\n<p>If we use the Synchronized keywords in any method then that method is Synchronized Method.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is used to lock an object for any shared resources.&nbsp;<\/li>\n\n\n\n<li>The object gets the lock when the synchronized method is called.&nbsp;<\/li>\n\n\n\n<li>The lock won\u2019t be released until the thread completes its function.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nAcess_modifiers synchronized return_type method_name (Method_Parameters) {\n\/\/ Code of the Method.\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"java-synchronized-method-example\"><strong>Java Synchronized Method Example:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Power{  \nsynchronized void printPower(int n){\/\/method synchronized\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n        System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n      Thread.sleep(500);  \n     }catch(Exception e){System.out.println(e);}  \n   }  \n }  \n}  \nclass Thread1 extends Thread{  \nPower p;  \nThread1(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(5);  \n}  \n}  \nclass Thread2 extends Thread{  \nPower p;  \nThread2(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(8);  \n}  \n}  \npublic class Synchronization_Example2{  \npublic static void main(String args&#x5B;]){  \nPower obj = new Power();\/\/only one object  \nThread1 p1=new Thread1(obj);  \nThread2 p2=new Thread2(obj);  \np1.start();  \np2.start();\n}  \n}\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-0:- 5^1 value: 5\nThread-0:- 5^2 value: 25\nThread-0:- 5^3 value: 125\nThread-0:- 5^4 value: 625\nThread-0:- 5^5 value: 3125\nThread-1:- 8^1 value: 8\nThread-1: - 8^2 value: 64\nThread-1:- 8^3 value: 512\nThread-1:- 8^4 value: 4096\nThread-1:- 8^5 value: 32768\n<\/pre><\/div>\n\n\n<p>Here we used synchronized keywords. It helps to execute a single thread at a time. It is not allowing another thread to execute until the first one is completed, after completion of the first thread it allowed the second thread. Now we can see the output correctly the powers 5 and 8 from n<sup>1<\/sup> to n<sup>5<\/sup>. Thread-0 completed then only thread-1 begin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"synchronized-block\"><strong>Synchronized Block<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suppose you don\u2019t want to synchronize the entire method, you want to synchronize few lines of code in the method, then a synchronized block helps to synchronize those few lines of code. It will take the object as a parameter. It will work the same as Synchronized Method. In the case of synchronized method lock accessed is on the method but in the case of synchronized block lock accessed is on the object.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsynchronized (object) {\n\/\/code of the block.\n}\nProgram to understand the Synchronized Block:\nclass Power{  \nvoid printPower(int n){ \nsynchronized(this){ \/\/synchronized block\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n        System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n      Thread.sleep(500);  \n     }catch(Exception e){System.out.println(e);}  \n   }  \n }  \n}  \n}\n  \nclass Thread1 extends Thread{  \nPower p;  \nThread1(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(5);  \n}  \n  \n}  \nclass Thread2 extends Thread{  \nPower p;  \nThread2(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(8);  \n}  \n}  \n  \npublic class Synchronization_Example3{  \npublic static void main(String args&#x5B;]){  \nPower obj = new Power();\/\/only one object  \nThread1 p1=new Thread1(obj);  \nThread2 p2=new Thread2(obj);  \np1.start();  \np2.start();\n\n}  \n}\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-0:- 5^1 value: 5\nThread-0:- 5^2 value: 25\nThread-0:- 5^3 value: 125\nThread-0:- 5^4 value: 625\nThread-0:- 5^5 value: 3125\nThread-1:- 8^1 value: 8\nThread-1:- 8^2 value: 64\nThread-1:- 8^3 value: 512\nThread-1:- 8^4 value: 4096\nThread-1:- 8^5 value: 32768\n<\/pre><\/div>\n\n\n<p>In this example, we didn\u2019t synchronize the entire method but we synchronized few lines of code in the method. We got the results exactly as the synchronized method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"static-synchronization\"><strong>Static Synchronization<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In java, every object has a single lock (monitor) associated with it. The thread which is entering into synchronized method or synchronized block will get that lock, all other threads which are remaining to use the shared resources have to wait for the completion of the first thread and release of the lock.<\/li>\n\n\n\n<li>Suppose in the case of where we have more than one object, in this case, two separate threads will acquire the locks and enter into a synchronized block or synchronized method with a separate lock for each object at the same time. To avoid this, we will use static synchronization.<\/li>\n\n\n\n<li>In this, we will place synchronized keywords before the static method. In static synchronization, lock access is on the class not on object and Method.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsynchronized static return_type method_name (Parameters) {\n\/\/code\n}\nOr \nsynchronized static return_type method_name (Class_name.class) {\n\/\/code\n}\n\nProgram without Static Synchronization:\nclass Power{  \n synchronized void printPower(int n){ \/\/static synchronized method\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n     System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n      Thread.sleep(400);  \n     }catch(Exception e){}  \n   }  \n  \n }  \n}    \nclass Thread1 extends Thread{  \nPower p;  \nThread1(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(2);  \n}  \n  \n}\n\nclass Thread2 extends Thread{  \nPower p;  \nThread2(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(3);  \n} \n}  \n\nclass Thread3 extends Thread{  \nPower p;  \nThread3(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(5);  \n}  \n} \n\nclass Thread4 extends Thread{ \nPower p;  \nThread4(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(8);  \n}  \n} \n\npublic class Synchronization_Example4{  \npublic static void main(String args&#x5B;]){ \nPower ob1 = new Power(); \/\/first object\nPower ob2 = new Power(); \/\/second object\nThread1 p1 = new Thread1(ob1);  \nThread2 p2 = new Thread2(ob1); \nThread3 p3 = new Thread3(ob2);\nThread4 p4 = new Thread4(ob2);\n\np1.start();  \np2.start();\np3.start();\np4.start();\n}  \n}\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-2:- 5^1 value: 5\nThread-0:- 2^1 value: 2\nThread-2:- 5^2 value: 25\nThread-0:- 2^2 value: 4\nThread-2:- 5^3 value: 125\nThread-0:- 2^3 value: 8\nThread-2:- 5^4 value: 625\nThread-0:- 2^4 value: 16\nThread-2: - 5^5 value: 3125\nThread-0: - 2^5 value: 32\nThread-3:- 8^1 value: 8\nThread-1:- 3^1 value: 3\nThread-3:- 8^2 value: 64\nThread-1:- 3^2 value: 9\nThread-3:- 8^3 value: 512\nThread-1:- 3^3 value: 27\nThread-3:- 8^4 value: 4096\nThread-1:- 3^4 value: 81\nThread-3:- 8^5 value: 32768\nThread-1:- 3^5 value: 243\n<\/pre><\/div>\n\n\n<p>If you observe the above results Thread-0, Thread-1 belongs to object-1 and Thread-2, Thread-3 are belonging to Object-2. So, there is no interference between thread 0 and 1 because of the same object (obj1). In the same way, there is no interference between Thread 2 and 3 because they belong to the same object (obj2). But if you observe there is interference between Thread 0 and 2, same as there is interference between Thread 1 and 3. To rectify this problem we will use static synchronization.<\/p>\n\n\n\n<p><strong>Program with static synchronization:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Power{  \n synchronized static void printPower(int n){ \/\/static synchronized method\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n     System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n      Thread.sleep(400);  \n     }catch(Exception e){}  \n   }  \n  \n }  \n}    \nclass Thread1 extends Thread{  \nPower p;  \nThread1(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(2);  \n}  \n  \n}\n\nclass Thread2 extends Thread{  \nPower p;  \nThread2(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(3);  \n} \n}  \n\nclass Thread3 extends Thread{  \nPower p;  \nThread3(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(5);  \n}  \n} \n\nclass Thread4 extends Thread{ \nPower p;  \nThread4(Power p){  \nthis.p=p;  \n}  \npublic void run(){  \np.printPower(8);  \n}  \n} \n\npublic class Synchronization_Example4{  \npublic static void main(String args&#x5B;]){ \nPower ob1 = new Power(); \/\/first object\nPower ob2 = new Power(); \/\/second object\nThread1 p1 = new Thread1(ob1);  \nThread2 p2 = new Thread2(ob1); \nThread3 p3 = new Thread3(ob2);\nThread4 p4 = new Thread4(ob2);\n\np1.start();  \np2.start();\np3.start();\np4.start();\n}  \n}\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-0:- 2^1 value: 2\nThread-0:- 2^2 value: 4\nThread-0:- 2^3 value: 8\nThread-0:- 2^4 value: 16\nThread-0:- 2^5 value: 32\nThread-1:- 3^1 value: 3\nThread-1:- 3^2 value: 9\nThread-1:- 3^3 value: 27\nThread-1:- 3^4 value: 81\nThread-1:- 3^5 value: 243\nThread-2:- 5^1 value: 5\nThread-2:- 5^2 value: 25\nThread-2:- 5^3 value: 125\nThread-2:- 5^4 value: 625\nThread-2:- 5^5 value: 3125\nThread-3:- 8^1 value: 8\nThread-3:- 8^2 value: 64\nThread-3:- 8^3 value: 512\nThread-3:- 8^4 value: 4096\nThread-3:- 8^5 value: 32768\n<\/pre><\/div>\n\n\n<p>In this static synchronization, we can observe there is no interference between Thread-0 and Thread-2 same as there is no interference between Thread-1 and 3. The next thread is executing after the previous thread completion or releasing lock only.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inter-thread-communication\"><strong>Inter \u2013 Thread Communication<\/strong><\/h2>\n\n\n\n<p>Inter \u2013 Thread communication or cooperation is a communication of two or more threads with each other. It can be done by using the following methods.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>wait()<\/li>\n\n\n\n<li>notify()<\/li>\n\n\n\n<li>notifyAll()<\/li>\n<\/ul>\n\n\n\n<p><strong>Why we need Inter \u2013 Thread Communication?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>There is a situation on the thread that keeps on checking some conditions repeatedly, once that condition satisfies thread moves with the appropriate action. This situation is known as <strong>polling.<\/strong> This is a wastage of CPU time, to reduce the wastage of CPU time due to polling, java uses Inter \u2013 Thread Communication Mechanism.<\/li>\n\n\n\n<li>wait(), notify(), notifyAll() methods must be called within a synchronized method or block otherwise program will compile but when you run it, it will throw illegal monitor State Exception.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Power{  \nvoid printPower(int n){\n   int temp = 1;\n   for(int i=1;i&amp;lt;=5;i++){ \n     System.out.println(Thread.currentThread().getName() + &quot;:- &quot; +n + &quot;^&quot;+ i + &quot; value: &quot; + n*temp);\n     temp = n*temp;\n     try{  \n        this.wait();    \/\/wait placed outside of the synchronized block or method\n      Thread.sleep(500);  \n     }catch(Exception e){System.out.println(e);}  \n   }  \n  \n }  \n}  \n\n<\/pre><\/div>\n\n\n<p><strong>&nbsp;Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThread-0:- 5^1 value: 5\njava.lang.IllegalMonitorStateException\nThread-0:- 5^2 value: 25\njava.lang.IllegalMonitorStateException\nThread-0:- 5^3 value: 125\njava.lang.IllegalMonitorStateException\nThread-0:- 5^4 value: 625\njava.lang.IllegalMonitorStateException\nThread-0:- 5^5 value: 3125\njava.lang.IllegalMonitorStateException\nThread-1:- 8^1 value: 8\njava.lang.IllegalMonitorStateException\nThread-1:- 8^2 value: 64\njava.lang.IllegalMonitorStateException\nThread-1:- 8^3 value: 512\njava.lang.IllegalMonitorStateException\nThread-1:- 8^4 value: 4096\njava.lang.IllegalMonitorStateException\nThread-1:- 8^5 value: 32768\njava.lang.IllegalMonitorStateException\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\">\n<li>wait () Method<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It causes the current thread to place itself into the waiting stage until another thread invokes the notify() method or notifyAll() method for this object.<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>notify () Method<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This method wakes up a single thread called wait () on the same object. If there is more than one thread that is waiting on this same object, then any one of them arbitrarily chosen to be awakened. Here awakened thread will not able to proceed until the current thread release lock. If any threads are trying to get the lock on this object then the awakened thread will also compete with them in the usual manner.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<p>public final void notify()<br><\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>notify All() Method<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rather than a single thread, it will wake up all the threads waiting on this object monitor. The awakened thread will not able to proceed until the current thread releases the lock. Again, these awakened threads need to compete with all other threads which are trying to get the lock on this object.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<p>public final void notifyAll()<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-drawback-of-synchronization-mechanism\"><strong>The Drawback of Synchronization Mechanism&nbsp;<\/strong><\/h2>\n\n\n\n<p>Synchronization Mechanism shows<strong> <\/strong>less performance.<br>Let\u2019s consider an example, if there are five process P1, P2, P3, P4, P5 that are waiting to get the shared resources to access only one thread at a time so, all other processes are in waiting condition, the last process has to wait until all other processes to be complete. So, we have to use the synchronization concept where we will get inconsistent results.<\/p>\n\n\n\n<p>If you are interested in learning more about Java visit <a data-type=\"URL\" data-id=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\" href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\">Great Learning Academy<\/a>.<\/p>\n\n\n\n<p>Engaging in the study of Java programming suggests a keen interest in the realm of software development. For those embarking upon this journey with aspirations towards a career in this field, it is recommended to explore the following pages in order to acquire a comprehensive understanding of the development career path:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-cyan-bluish-gray-background-color has-background\"><tbody><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/certificates\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses certificates<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/placements\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses placements<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/syllabus\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses syllabus<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/fees\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses fees<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/eligibility\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses eligibility<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads. Why we use Synchronization Types of Synchronization Synchronization is [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":27252,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"content_type":[],"class_list":["post-27014","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Synchronization in Java<\/title>\n<meta name=\"description\" content=\"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Synchronization in Java\" \/>\n<meta property=\"og:description\" content=\"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T04:21:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-13T08:38:59+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1254\" \/>\n\t<meta property=\"og:image:height\" content=\"836\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Synchronization in Java\",\"datePublished\":\"2023-11-08T04:21:06+00:00\",\"dateModified\":\"2025-01-13T08:38:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/\"},\"wordCount\":1252,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/iStock-171274029.jpg\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/\",\"name\":\"Synchronization in Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/iStock-171274029.jpg\",\"datePublished\":\"2023-11-08T04:21:06+00:00\",\"dateModified\":\"2025-01-13T08:38:59+00:00\",\"description\":\"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/iStock-171274029.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/iStock-171274029.jpg\",\"width\":1254,\"height\":836,\"caption\":\"Hand holding gears\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/synchronization-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Synchronization in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Synchronization in Java","description":"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Synchronization in Java","og_description":"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).","og_url":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2023-11-08T04:21:06+00:00","article_modified_time":"2025-01-13T08:38:59+00:00","og_image":[{"width":1254,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Synchronization in Java","datePublished":"2023-11-08T04:21:06+00:00","dateModified":"2025-01-13T08:38:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/"},"wordCount":1252,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/","url":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/","name":"Synchronization in Java","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg","datePublished":"2023-11-08T04:21:06+00:00","dateModified":"2025-01-13T08:38:59+00:00","description":"Java Synchronization Tutorial: Synchronization in Java is built on top of the locking mechanism, this locking mechanism is taken care of by Java Virtual Machine (JVM).","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg","width":1254,"height":836,"caption":"Hand holding gears"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/synchronization-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Synchronization in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg",1254,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg",1254,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029.jpg",1254,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-640x836.jpg",640,836,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/iStock-171274029-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads. Why we use Synchronization Types of Synchronization Synchronization is&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/27014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=27014"}],"version-history":[{"count":19,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/27014\/revisions"}],"predecessor-version":[{"id":104500,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/27014\/revisions\/104500"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/27252"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=27014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=27014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=27014"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=27014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}