Java Multi-Threading Question: Download Java Multi-Threading PDF

Explain volatile?

Tweet Share WhatsApp

Answer:

When more than one threads access the same variable then each thread will maintain its own copy of that variable in the form of local cache.
When a thread is changing the value of variable, it is actually changing the local cache not the main variable memory.
Every thread which is using the same variable doesn’t know anything about the values changed by another thread.
To overcome this problem, if you declare a variable as volatile, then whenever a thread is changing the value of a volatile, it is actually changing to the main memory. So, all other threads which are accessing the same variable can get the changed value.

Download Java Multi-Threading PDF Read All 36 Java Multi-Threading Questions
Previous QuestionNext Question
What is the priority for Garbage collector thread?What is daemon thread and how it differs from user thread?