Multithreaded Programming:
1. Call the Wait () method of an object, which is equivalent to having the current thread hand over the object's monitor (lock, Monitor), and then into a wait state, waiting for subsequent locks on the object
(The Sleep method in the thread class causes the current thread to suspend execution for a period of time, allowing other threads to continue executing, but it does not release the object lock);
2. If you call the Wait () method of an object, the current thread must have the monitor (that is, the lock) of the object, so calling the wait () method must be done either in a synchronous block or in a synchronous method (synchronized block or Synchronized method).
Call the Notify () method of an object, and the current thread must also have the monitor for that object, so calling the Notify () method must be done in a synchronous block or synchronous method (synchronized block or Synchronized method)
3. For a simple example: if there are three threads Thread1, Thread2, and Thread3 are waiting for the object Objecta Monitor, this time THREAD4 has the object objecta the monitor, When the Objecta.notify () method is called in Thread4, only one of Thread1, Thread2, and Thread3 can be awakened.
Note that being awakened does not mean that the OBJECTA Monitor is acquired immediately. If the Objecta.notifyall () method is called in Thread4, the three threads of Thread1, Thread2, and Thread3 will be awakened. As for which thread is next able to get to objecta monitor, it depends on the operating system's schedule.
Multi-threaded Notes Little note