• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic