This is my code which waits for notification from some other thread. In case, if i dont want it to be indefinitely waiting for the notification, how can i give a timer value to keep waiting till that time and once that time is reached, come out of wait().
vinod:I have tried wait(time) API. Can it be done without this using Timer class?
Yeah it can be done via the Timer class but i would not suggest it. The reason being that you will start a new thread(if Timer is not already used) to keep a watch on the running thread. More so, if the only task of the timer is to notify when the time lapses. The best way is to use the timed wait method.
Pawan: whenever you declare wait method in any method of an object, you have to declare it synchronized, otherwise an unchecked exception will be thrown.