Kousik Majumder wrote:HI Steve,
Thank you for your quick reply. But I still do not understand what code should I write to wait for any element to be inserted in stack(without using Object.wait()) and also how do I handle the situation when all the elements are popped up already.
Thanks,
Kousik
I gave some hints there. Look up java.util.concurrent.Semaphore, or java.util.concurrent.locks.Lock and java.util.concurrent.locks.Condition to see how they get used.
How do you deal with 'when all the elements are popped up already?' Define what you mean by when all the elements are popped, what is the difference between that and the case when the stack is empty and you should wait to pop the next item? Once you answer that you can decide what you want to do when you reach that situation.