I have a bit problems to post my topics since I accidently add the topics when I push the tab-button to format my code. Sorry! Here is what I want to say:
In the Bonus Mock Exam that I got with the certification book for Java 5, the following code was shown and it was asked what it did. The answer was that every second (approximately) each of the three Listeners will report a temperature. I have tried this and it is true, but I do not understand why. I think that only one of the threads should report a temperature every second since the block of code with the wait-method in the run-method of the Listener class is synchronized on the same forecast object. Hence, only one of the Listeners can be waiting to get notified by the forecaster?
What am I missing?
(sorry if the code is a bit ugly formatted, did not dare pushing the tab again ;-))
Many thanks Hanna
EDIT by mw: Added Code Tags and disabled smilies. [ April 09, 2007: Message edited by: marc weber ]
Joined: Mar 13, 2007
Ok, and now I see that the for-loops turn to smilies...hm..
It is for-loops without any declarations that it is supposed to be...
Let's think other way. Every second Forecaster notifies all available listeners. (Three Listeners are created in main). When Forecaster is sleeping for a second, all available listeners get a chance to run.