Edward Chen wrote:As we know, we can use synchronized to instance method and class static method. Synchronized means one thread has to hold lock (monitor). Then in the both synchronized method (static and instance), the lock (monitor) is same ?
No. There are two locks namely "class lock" & "instance lock". "class lock" is associated with the Class object of that class and the instance lock is associated with the object itself. So you get instance lock for each instance you create. Static blocks synchronize on "class lock" while instance lock synchronizes on instance (object) lock.
Mohammed Yousuff wrote:
in above code synchronized block was done in Class Level and the entire class was LOCKED.
I don't know what you mean by "entire class was LOCKED.. " but you still able to invoke any other instance methods (if any) of a given instance of that class.And the reverse is also true for instance locks, that is you are still able to invoke static/non-synchronized instance methods in case of instance lock.
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
The WEB SERVICES and JAX-RS Coursehttps://coderanch.com/t/690789/WEB-SERVICES-JAX-RS