أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
In java why wait() and notify() method are present in object class but used in Thread?
wait()=
If threads calls wait() on any object it immeditaly release the lock of the particular object and entered in to waiting state .
notify()=
If threads calls notify() on any object it release the lock of the particular object butmay not immeditaly .
These methods are communication mechanism between two threads in java. object class is the correct place to make them available for every object. and locks are made available ob per object basis. and these () works on locks,and locks are in object.
Every object in java has only one lock(monitor) and wait(),notify(),notifyAll() are used for monitor sharing thats why they are part of object class rather than Thread class. These methods works on the locks and locks are associated with Object and not Threads
Because Locks are made available on per Object basis, which is another reason wait and notify is declared in Object class rather then Thread class.
wait means it's having some time to wait.exceptions used in java.that is very big concept in java.checked exception and unchecked execption.wait is checketed exception and thread is unchecked execpetion.