Saturday, 23 April 2016

volatile vs. synchronized keyword


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.