Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS

 
Hanna Barenthin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

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 ]
 
Hanna Barenthin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Patrick Patel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hanna Barenthin:
Ok, and now I see that the for-loops turn to smilies...hm...

Yes, ;) will turn into a smilie, unless you check the box to "Disable smilies in this post." Alternatively, you can just add a space between the semicolon and parenthesis.

Note that you can edit your own posts by clicking on the paper/pencil icon.
[ April 09, 2007: Message edited by: marc weber ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic