Explain volatile?
Submitted by: AdministratorWhen 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.
Submitted by: Administrator
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.
Submitted by: Administrator
Read Online Java Multi-Threading Job Interview Questions And Answers
Top Java Multi-Threading Questions
☺ | Explain deadlock? |
☺ | What is the sleep() method Data type for the parameter? |
☺ | Explain the difference between preemptive scheduling and time slicing? |
☺ | How many threads at a time can access a monitor? |
☺ | Name the default thread at the time of starting the program? |
Top Java Programming Language Categories
☺ | Core Java Interview Questions. |
☺ | Hibernate Interview Questions. |
☺ | Advanced Java Interview Questions. |
☺ | IBM WebSphere Interview Questions. |
☺ | Spring Framework Interview Questions. |