I came across these statements
=> The static synchronized methods of the same class always block each
other as only one lock per class exists. So no two static synchronized
methods can execute at the same time.
=> When a synchronized non static method is called a lock is obtained on
the object. When a synchronized static method is called a lock is obtained
on the class and not on the object.
I wrote these simple programs to understand how exactly it works.
1. TestStaticSync.testSync1() - Class level lock is obtained for all static synchronized methods and the second thread is waiting for the Class lock to be released to invoke TestStaticSync.testSync1(). Hence program output for synchronized methods are shown below