"Java Multithreaded Programming Practical Guide (Core)" Q&A (updated one after another)

ask:
Hello author, see the Visibility section, should the toCancel variable defined here be of static type to be effective?

 

answer:

The variable toCancel needs to be modified with volatile to achieve the expected effect. In Chapter 2, we did not use volatile modification to show the visibility problem. Chapter 3 explains why in detail.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326688200&siteId=291194637