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.
The lock on the object and the lock on the class don't interfere with each other.
It means, a thread accessing a synchronized non static method, then :
- The other thread can access the synchronized static method at the same time.
AND
- Can't access the synchronized non static method.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.