参见Synchronized Methods:Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.也就是说加锁的第二个作用是保证了内存壁垒。