Training Institute in Electronic City Bangalore

Training Institute in Electronic City Bangalore
Training Institute in Electronic City Bangalore

Difference between synchronized and volatile keyword in Java?

·         The volatile keyword in Java is a field modifier while synchronized modifies code blocks and methods.
·         Synchronized obtains and releases the lock on monitor’s Java volatile keyword doesn't require that.
·         Threads in Java can be blocked for waiting for any monitor in case of synchronized, that is not the case with the volatile keyword in Java.
·         Synchronized method affects performance more than a volatile keyword in Java.
·         Since volatile keyword in Java only synchronizes the value of one variable between Thread memory and "main" memory while synchronized synchronizes the value of all variable between thread memory and "main" memory and locks and releases a monitor to boot. Due to this reason synchronized keyword in Java is likely to have more overhead than volatile.
·         You cannot synchronize on the null object but your volatile variable in Java could be null.

·         From Java 5 writing into a volatile field has the same memory effect as a monitor release, and reading from a volatile field has the same memory effect as a monitor acquire

[Multithreading Interview Questions]

We recommend you take Big Data Hadoop class room training at eMexo Technologies in electronic city, Bangalore to learn more about Big Data Hadoop.

0 Comments:

© Blogger Templates | Webtalks