Volatile variable tell JVM threads to read the value from main memory, thread should nor use cached value in its own stack.

Specially, volatile variable is used to signal threads.

1
2
3
4
5
private volatile boolean shutdown = false;

while(!shutdown){
 //To do
}