would like to ask you gods, I want to get a use case of Volatile, this is the following code, according to the following code,
if I set the jvm run parameter to-server, it should always run, the program will enter an endless loop, but in fact
does not, this is why?
public class Main {
public static void main(String[] args) {
VolatileThread volatileThread = new VolatileThread();
volatileThread.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
volatileThread.setContinue(false);
}
}
public class VolatileThread extends Thread{
private boolean isContinue = true;
public void setContinue(boolean aContinue) {
isContinue = aContinue;
}
@Override
public void run() {
while (isContinue){
System.out.println("Continue");
}
System.out.println("end");
}
}
I use IDEA to run the program. The following is a picture of my setting of running parameters:
is my parameter not set correctly? Or is the example incorrect?