I am learning Advanced
Java & am fairly confused on this 1 topic of using the wait() & notify() methods for
thread communication in concurrency programming with the sync block & sync keyword (synchronization)
I tried going through all articles I could find on the net but nothing gives a conclusive understanding as to how to use these methods on threads locking on certain objects, i have a simple code here wherein I am trying to get a thread to suspend execution for some time while another thread on the same object carries out some tasks, which when over notifies the 1st thread to resume operation. I have locked the threads on a particular object variable within my class instance & am using it as the object whose condition is to be monitored for suspending & resuming the thread.
My Code:
My Main:
The thread waits as intended but the notify does not work, however if I use "this" as object to monitor in general & then call the methods as
the notify method works as intended, can someone explain what I am doing wrong ?? as is why can I not set the object to monitor as the Integer variable "i" ??
any input would be much appreciated.