Possibly similar question:
Do you ever use the volatile keyword in Java?
Because the compiler can't optimise volatile variables.
volatile tells the compiler that the variable can change at any time. Therefore, it can't assume that the variable won't change and optimise accordingly.
volatile