Volatile Keyword in Java

Advertisements

Synchronized Keyword in Java Static Block in Java

Volatile Keyword in Java

If the variable keep on changing such type of variables we have to declare with volatile modifier. Volatile is a modifier applicable only for variables but not for method and class.

If a variable declared as volatile then for every thread a separate local copy will be created. Every intermediate modification performed by that thread will takes place in local copy instead of master copy. Once the value got finalized just before terminating the thread the master copy value will be updated with local stable value.

Advantage of Volatile

The main advantage of Volatile keyword is we can resolve data inconsistency problems.

Dis-Advantage of Volatile

The main dis-advantage of Volatile keyword is, crating and maintaining a separate copy for every thread, increases complexity of the programming and effects performance of the system. Hence if there is no specific requirement it is never recommended to use volatile keyword, and it is almost outdated keyword.

Note: Volatile variable means its value keep on changing where as final variable means its value never changes. Hence final-Volatile combination is illegal combination for variables.


Synchronized Keyword in Java Static Block in Java

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements