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.
  Modified On Dec-14-2017 01:20:11 AM

Leave Comment