Tag: Wait timed must not block Java end requires object
The difference between sleep (), yield (), wait (), join ()
1.sleep () Frees the CPU, does not release the lock
Causes the current thread to enter a blocking state that does not execute within the specified time.
2.yield () Frees the CPU, does not release the lock
Returns the current thread to its executable state, with the possibility of returning to the executable state and executing it immediately. Yield can only enable threads with the same sibling priority or higher priority to have an opportunity to execute.
3.wait () Release the CPU, release the lock
After calling the object's Wait method, the Rongguo notify () or Notifyall () method is required to wake up.
The invocation of the object's Wait (), notify (), Notifyall () is based on the assumption that the current thread must hold a lock on the object, so these three methods must be called in the synchronized function or synchronized block.
4.join () Release the CPU, release the lock
Wait for the thread that calls the join () method to execute the end, and then proceed down.
The difference between Java multithreaded sleep (), yield (), wait (), join ()