Home > DeveloperSection > Articles > Synchronization in Java

Synchronization in Java

Java Java  J2EE 
0 Comment(s)
 1152  View(s)
Rate this:

Synchronization in Java

It will only class level variable or data can be shared .We can create single object for each thread but we have some condition where we have to share the same object with all threads. So that synchronization is necessary between threads.

For Example:
public class SynchronizationEx
private int x;
private int y;
synchronized int(int a,int b)
return x+y;

In java every object  is having a one implicit 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.
Synchronization  degrade the performance of thread.

Don't want to miss updates? Please click the below button!

Follow MindStick