I am afraid not. b.wait() means the thread b is waiting.
You can use the join() method in case you wish that thread threadA should wait for thread b to finish its work and then intimate thread threadA when done.
Sorry, but b.wait() means that the CALLER (here, a) should wait until someone calls b.notify(). You don't show the code for b, but presumably the run() method in the ThreadB class calls notify() -- otherwise "a" would wait forever.
The object you call wait() on is used as a kind of "message board;" the word people usually use is "monitor."
No, line 8 says �Let the thread that is executing this code wait�. b refers to the object that has the wait set.Line 8 seems to be saying "Let b wait" and this conflicts with what the main says in Line 7.
No, the main thread is saying, �virtual machine, add me to the wait set of the object that little b is pointing to. Some other thread will remove me from the wait set.� Meanwhile, the other thread is executing the run method.It looks like when ThreadA calls b.wait(), ThreadA is really saying, "little b, go ahead and finish your job, I will be here waiting for you. Let me know when you are done.". Is this right?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |