Hi,
Synchronization means, it allows only one thread to access the instance.
For Example.-
public class Counter
{
int c = 0;
public void A()
{
c++;
}
public void B()
{
c--;
}
In above example, first time c is going to increment and second time c is going to decrement.
Unless you declare synchronization for these two methods, the result leaves to inconsistency.
We use two types of synchronization.
Using Synchronization keyword with method.
and synchronization block
synchronization
{
// some code here.
}
In two things, second one means synchronization block is best.
Thanks and Regards
Maruthi.