Always there is a confusion with volatile keyword in Java.

If any varibale is used across multiple threads then it is must to tag that with volatile ? . There are plenty of blogs talks about volatile but nothing gives the one shot answer. Most talks about Java version changes and relation with synchronized keyword.

Marking the method with synchronized will give the same effect of volatile?. I need clear distiction between volatile, synchronized, atomic primitives and references with respect to multi-threaded application.

0 Answers