What is the use of voltile specifier

Showing Answers 1 - 2 of 2 Answers

Sumit Malik

  • May 31st, 2006
 

Hi... SrinivaS We define a variable as volatile when we are dealing with threads.Declaring variable as volatile tell the compiler to fetch fresh value of variable everytime when its requested as per execution of program.During execution compiler caches the value of variable for efficiency reason and given that value of variable as and when required in the program but not in case if variable is declared as volatile.It might possible that when one thread is reading the value of variable then at the same time another thread update the value of variable which leads to inconsistency.To avoid such circumstances we use volatile with variable.So when everytime request is made for fetching the value of variable then compiler gives fresh value of variable.This also lead to certain optimization that another thread will not change the value of variable in random fashion.I hope this will clear your doubts.Do let me know about it .ThanksSumit Malik

  Was this answer useful?  Yes

Hi Friends

Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.

ok bye.........

keeps smiling and mailing

bora_srinivasarao@yahoo.co.in

Note:If any one want java materials like e-books,faq's send a mail to my id.if any doubts regarding java send a mail to my id, if possible i will send answers.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions