Monday, April 23, 2018

10 points about synchronized in Java



1. Synchronized can only be applied to methods and code block, you can not make a variable, a class or an interface synchronized in Java.

2. When a thread enters a synchronized block or method, it acquire lock on the object method has been called. Similarly when thread exits the block, both normally or abruptly due to any error, it relinquish the lock.

3. Synchronized keyword not only provide mutual exclusion, but also provides visibility guarantee. Memory barriers are updated when thread enter or exits synchronized block or method. 

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.