---
title: "Synchronization in Java"  
description: "Synchronization is required when more than one thread sharing the same resources ."  
author: "Anupam Mishra"  
published: 2015-11-04  
updated: 2017-12-14  
canonical: https://www.mindstick.com/articles/11901/synchronization-in-java  
category: "java"  
tags: ["java", "j2ee"]  
reading_time: 1 minute  

---

# Synchronization in Java

It will only [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) level [variable](https://www.mindstick.com/blog/11493/what-is-a-variable) or data can be [shared](https://www.mindstick.com/forum/155587/what-is-shared-assembly) .We can create single object for each thread but we have some [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) where we have to share the same object with all threads. So that [synchronization](https://www.mindstick.com/articles/11983/synchronization-in-c-sharp) is necessary between threads.

##### For Example:

> ```
> public class SynchronizationEx{private int x;private int y;synchronized int(int a,int b){this.x=a;this.y=b;return x+y;}}
> ```

In [java](https://www.mindstick.com/interview/22908/what-are-java-string-class-method) every object is [having](https://www.mindstick.com/forum/1950/having-trouble-showing-gridview) a one [implicit](https://www.mindstick.com/interview/827/what-are-implicit-objects-list-them) lock on it i.e. called lock monitor. If any thread want to run any method then it have to get that lock and only one thread can enter in [synchronized method](https://www.mindstick.com/blog/304524/what-are-synchronized-methods-and-blocks-in-java).Synchronization degrade the performance of thread.

---

Original Source: https://www.mindstick.com/articles/11901/synchronization-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
