Friday, September 12, 2014

Volatile

Volatile is the keyword which can be applicable only for variables i.e. we can’t use for classes and methods. If the value of a variable is changing frequently such type of variables we have to declare with the keyword Volatile.
            For the Volatile variables JVM will create a separate private copy for every Thread. After completing entire transaction by the thread the final value should be updated in the master copy. So the value of Volatile variable is always stable i.e. At variable level we can achieve synchronization by using Volatile keyword.
            For every Thread maintaining a separate copy is always difficult, hence the performance of the system goes down.
            Volatile means the value keep on changing, but final means the value is not allowed to change hence volatile and final combination is useless.

No comments:

Post a Comment