Locking with synchronized block guarantee both atomicity and visibility.
Volatile variables can only guarantee visibility.
Use volatile variables only when :
1. Writes to variable don't depend on its current value
2. Locking is not required for other reasons
No comments:
Post a Comment
Note: only a member of this blog may post a comment.