File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic


Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 608 I'm busy messing around with threads and I decided to make a small game.It's not working well so far though.My cat thread isn't running.Also I'm not sure that I've used wait() and notify() correctly.

The idea is that I create a Mouse and cat class.Then I create a single Cat and multiple Mouse threads.When a mouse is created it gets put in a static hash map.I use math.random() in the Cat thread to create a random chance of the cat catching(and killing) a mouse.Not quite sure how I should go about this..Oh yes..also the idea is that there should only be one mouse running around at a time.The game is meant to end either when cheese=0 OR when the mice have all been killed...
I just can't seem to get the Cat thread to output anything....any suggestions??

[ December 29, 2008: Message edited by: Duran Harris ]

===>SCJP 1.5(72%)<===
Anthony Accioly

Joined: Dec 22, 2008
Posts: 16


Your program had several issues...
1) The program was freezing because everyone was waiting at the cat monitor
2) You forgot to interrupt the mouse thread once you killed it
3) The static HashMap approach wasen't really working

Here is a version of the program that seens to be working allright for me:

ps: There is a game development forum here at the saloon .


[ December 29, 2008: Message edited by: Anthony Accioly ]
[ December 29, 2008: Message edited by: Anthony Accioly ]
I agree. Here's the link:
subject: Threads
It's not a secret anymore!