Regarding the thread empty method body referencing static variables endlessly, unable to get the latest value of the variable

A few days ago, several big guys in the paddling group (901476449) were paddling, and suddenly a piece of code blew the horn of 13 for every big guy. as follows:

It is generally believed that after 3 seconds, it must be dead. Of course, our rookie thinks so too. The result is woooo~~ It's been two minutes and still running. .

After that, after the boss mentions (ridicizes) a point (sarcasm), add the keyword volatile

but why?

Volatile guarantees the visibility of different threads operating on this variable, that is, if a thread modifies the value of a variable, the new value is immediately visible to other threads. (Achieve visibility) 

And memory model related

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_36338555/article/details/103727179