This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS" Watch "Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS" New topic
Author

Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS

Hanna Barenthin
Greenhorn

Joined: Mar 13, 2007
Posts: 14
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

Joined: Mar 13, 2007
Posts: 14
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

Joined: Aug 25, 2006
Posts: 9
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with threads, PLEASE IGNORE MY PREVIOUS TOPICS
 
Similar Threads
Connection is failing at ObjectInputStream for Server
problem with wait()- notify()
It's about JavaBeans
blocking and waiting
Synchronization And Locks