where i use notifyall and where should i use notify
It depends on your requirement. Notify is for well, to notify only one thread which is waiting on a given object. And notifyall for notifying all the threads waiting on the given object. In notifyall you can't gurantee which thread will actually be picked by the JVM.