volatile variable in java

Solutions on MaxInterview for volatile variable in java by the best coders in the world

showing results for - "volatile variable in java"
Fanny
11 Sep 2018
1/* Volatile variable means that the variable will be directly read from
2and written to the computer's main memory and not to the CPU cache.
3
4In Java it is done using the volatile keyword.
5
6This is used in multithreaded applications. In multithreaded environment
7where each thread may copy the variable into caches of different cores.
8Thus making the data available to other threads inconsistent.
9*/
10
11public class SharedObject
12{
13  	public volatile int counter = 0;
14}