Reading a stale value after a newer value was read [duplicate]
问题 This question already has answers here : Reordering of reads (2 answers) Closed 2 months ago . Consider this example. We're having: int var = 0; Thread A: System.out.println(var); System.out.println(var); Thread B: var = 1; The threads run concurrently. Is the following output possible? 1 0 That is, the original value is read after the new value was read. The var isn't volatile. My gut feeling is that it's not possible. 回答1: You are using System.out.println that internally does a synchronized