difference between wait() and yield()

前端 未结 3 1574
情歌与酒
情歌与酒 2021-02-14 23:02

So far what I have understood about wait() and yield () methods is that yield() is called when the thread is not carrying out any task and lets the CPU execute some other thread

3条回答
  •  情深已故
    2021-02-14 23:52

    The first difference is that yield() is a Thread method , wait() is at the origins Object method inheritid in thread as for all classes , that in the shape, in the background (using java doc)

    wait()
    

    Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

    yield()
    

    A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.

    and here you can see the difference between yield() and wait()

提交回复
热议问题