What is the difference between sleep(long n) and wait(long n)?

learning target:

掌握 wait和sleep的区别

For example:

  • Master the difference between wait and sleep

Learning Content:

分析sleep和wait的区别

  1. sleep is a Thread method, and wait is a method of Object
  2. sleep does not need to be forced to be configured with synchronized, but the wait method must be used with synchronized
  3. sleep is sleeping, 不会释放锁对象and wait is waiting 会释放锁对象, and 这个线程会进入到Monitor的Waiting中等待被唤醒when the waiting thread in Waiting is called notify或者notifyall, 唤醒it will re-enter the EntryList in the Monitor object.重新竞争
    Insert image description here

Learning output:

Guess you like

Origin blog.csdn.net/m0_50677223/article/details/130789173