+ 1

What is different between Object.wait() and infinite while loop

Differenctiate Java programming Object.wait(); and while (true){ }

28th Sep 2019, 3:29 PM
Ajay Gaikwad
Ajay Gaikwad - avatar
2 Antworten
+ 1
Object.wait() if must used method in multithreading. Difference between Object.wait() and infinite while loop is that if you call wait() method on any thread it will releases aquaried resources, that should be used by other threads. If you run infinite loop then the resources held by thread or process are not released which might be required for other process. Hence infinite loop consumes resources even if they are not in use. But in Object.wait() case is totally opposite and it releases resources. While waiting and wakes up it receive signal from notify or notifyAll methods.
6th Jan 2020, 3:32 PM
Ajay Gaikwad
Ajay Gaikwad - avatar