InterviewSolution
Saved Bookmarks
| 1. |
Volatile keyword in Java |
||||||||||||||||||
|
Answer» A class can be made thread safe using the volatile keyword. This means that multiple threads can use the class instance or methods at the same time without any problem. The USAGE of the volatile keyword on a particular variable means the following:
An example of the volatile keyword is given as follows: class Shared { static volatile int value = 15; }In the above example, if there are any changes made by one thread then they are reflected in the other threads as WELL using the volatile keyword. Differences between volatile and synchronized Some of the differences between volatile and synchronized are given as follows:
|
|||||||||||||||||||