"One-minute knowledge" thread synchronization, thread scheduling
The difference between the sleep () and yield () methods of a thread
1
The sleep () method gives the other threads an opportunity to run without taking into account the priority of the thread, thus giving the lower-priority thread the chance of running;
The yield () method only gives the same priority or higher priority threads the opportunity to run;
2
Thread executes the sleep () method into a blocking (blocked) state,
The execution of the yield () method is then transferred to the Ready (ready) state;
3
The sleep () method declaration throws Interruptedexception,
The yield () method does not declare any exceptions;
4
The sleep () method is more portable than the yield () method (associated with operating system CPU scheduling).
Thread synchronization and thread scheduling-related methods
Wait ()
Causes a thread to be in a waiting (blocking) state and release the lock of the object being held;
Sleep ()
To make a running thread sleep, a static method that calls this method to handle the interruptedexception exception;
Notify ()
Waking a waiting state, of course, when calling this method, does not exactly wake up a waiting state of the thread, but rather by the JVM to determine which thread to wake, regardless of priority;
Notityall ()
Wakes all waiting-state threads, not locking objects to all threads, but letting them compete, and only the thread that gets the lock can enter the ready state;