Sleep is a method in thread, and wait is a method in object.
Sleep is a thread that goes into hibernation, waits for a period of time, enters the operational state, waits for the CPU to allocate resources and run. At the same time sleep process, it is possible to be a message between the threads, that is, it is possible for other objects to call his interrupt (), produce interruptedexception exception if your program does not catch this exception, the thread will terminate abnormally, Enter the terminated state, and if your program catches the exception, the program will continue to execute the Catch statement block (and possibly the finally statement block) and later code.
Note that the sleep () method is a static method, which means that he is only valid for the current object, and that by T.sleep () the T object enters sleep, it is wrong to make the current thread sleep instead of the t thread.
Wait is a member method of object, and once an object calls the Wait method, the process must be woken up with the Notify () and Notifyall () methods, and if the thread has a synchronization lock on one or some of the objects, after the call to wait () This thread releases all of the synchronization resources it holds, not the object that is called the Wait () method. The wait () method can also be generated by other objects calling the interrupt () method during the wait process.
In fact, the main difference between sleep and wait is that sleep is dormant, it does not release the lock, and the wait method frees the lock so that other threads can use the synchronization control block or method.
The difference between wait and sleep in Java (multithreaded programming)