Answers for "volatile variable in java"

0

volatile variable in java

/* Volatile variable means that the variable will be directly read from
and written to the computer's main memory and not to the CPU cache.

In Java it is done using the volatile keyword.

This is used in multithreaded applications. In multithreaded environment
where each thread may copy the variable into caches of different cores.
Thus making the data available to other threads inconsistent.
*/

public class SharedObject
{
  	public volatile int counter = 0;
}
Posted by: Guest on July-22-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language