top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: How does volatile variable works in Java?

+1 vote
440 views
Java: How does volatile variable works in Java?
posted Sep 4, 2013 by Arvind Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Volatile variable in Java is a special variable which is used to signal threads, by making a variable volatile using volatile keyword in Java, application programmer ensures that its value should always been read from main memory and thread should not used cached value of that variable from there own stack. Volatile variable also guarantees "happens-before" relationship, which means not only other thread has visibility of latest value of volatile variable but also all the variable seen by the thread which has updated value of volatile variable before this threads sees it.

answer Sep 4, 2013 by Vinay Shukla
...