Hi,
I have a question or rather an exercise.
You have two threads, one is printing odd numbers and one is printing even number continuously. Manage them in such a way that they print numbers in sequence.
I understand that this could be done in many ways for e.g. through Semaphore, explicit locks, etc.
I have prepared its solution through wait()/notify()/notifyAll() but its not working. Following is the code:
Assumptions:
1) I am limiting the numbers to 15.
2) Also I am storing the numbers in a List and printing it at the end.
3) I am taking
counter as a shared variable.
I have broken my head
on this code for several days but couldn't solve this
. Please do help me and do let me know what's wrong in this code which I have written. I am having nightmares. Everyday I try to solve this problem and bang my head for several hours in this but to of avail and everyday I feel disappointed. This code would help me in clarifying my concept of wait()/notify()/notifyAll().
Thanks,
Sid.