The difference and connection of sleep, yield, wait, join in multithreading

/**
 * Summary:
 * 1.sleep(): Who calls, who sleeps, will not release the object lock, the thread can be synchronized, you can use interrupt() to force interrupt sleep
 * 2.sleep(): It is a static state of the Thread class method, need to catch exceptions
 * 3. join() calls wait() internally, it will give the lock, and sleep() will keep the lock all the time. join() The parent thread waits for the child thread to finish running before starting to run.
 * 4. When calling the wait() method, the thread will give up the object lock and enter the waiting lock pool waiting for this object. Only the notify() method is called for this object Only after this thread enters the object lock pool to prepare
 * 5.yield() The function of yield() method is to give up the current CPU resources and give it to other tasks to occupy CPU time. Note: The time to give up is uncertain, and the CPU time slice may be regained after a while

 */

Java development, only continuous attempts and persistent summaries, there are no shortcuts.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325640495&siteId=291194637