Since the execution from one thread to another thread always changes at runtime, and you can solve the problem of the producer-consumer, the problem cannot be simulated at compile time, since the consumer consumes the buffer after the buffer is consumed, it notifies the producer at that time and before at that time, the manufacturer will wait differently, there is an exception, so the whole logic of these methods is inside synchronized blocks
source
share