What is synchronization? When do we use it?
Java supports multiple threads to be executed. This may
cause two or more threads to access the same fields or
objects. Synchronization is a process which keeps all
concurrent threads in execution to be in synch.
Synchronization avoids memory consistence errors caused
due to inconsistent view of shared memory. When a
method is declared as synchronized; the thread holds the
monitor for that method's object If another thread is executing the synchronized method, your thread is blocked until that thread releases the monitor.