Why we must use “while” for checking race condition not “if”
问题 I read the following code in "Thinking in java". synchronized(obj) { while (condition_not_matched) { obj.wait(); } //continue dosomething(); } What I think: Use "if" is OK, because the "wait" means it must get the obj's lock monitor, and only one thread can executed here. (1)Why here use "while (condition)" not "if" ? (2)What happend when executed "obj.wait()"? Does the currrent thread release the lock of "obj"? (3)And when another thread executed "obj.notify()", what happend of the previous