Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ait and notify again  RSS feed

 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!!
Well though I looked around in the ranch for something clear on wait and notify 'twas futile..
so pardners.. can you show this dude how to throw the lasso over the wait and notify methods in threads?
I need a simple illustration, with example if you got room, on how wait and notify can be used.
Thanks everyone..
Regds
Lupo
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This in the Java Tutorial was goood for me.
[ November 02, 2002: Message edited by: Jose Botella ]
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tanx jose!!
Well I sure did look @ the example in the tut.. but those guys are too fast for me in drawing thier guns and shooting.. more so they are too fast fer me to note the tactic in throwing the lasso..
anyway.. if there is anyone who can explain better.. please do so!!!
bye all.
Lupo
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait() and notify() are called on objects not threads.
And, these both can be called from within synchronized code.
In a plain English, wait() for a current thread means that "it's not my time to do things, let's go for a cup of coffe until I get notified" while notify() means "hey, let's get back to work"
More technical explanation:
when thread obtains lock on an object (gets into block of synchronized code) no other thread can get there at the same time. If you want this thread to wait for something (eg. some field value is not set yet) you call wait() on the Object (not thread, check java.lang.Object in API) what means that current thread is not a lock owner anymore and other threads can enter synchronized code to do things. When notify() is called all waiting threads compete to get object's lock and which is lucky no one can predict.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few corrections to raimondas.
notify only notifies/wakes 1 thread waiting on the object. notifyAll will notify/wake them all.
[ November 06, 2002: Message edited by: CL Gilbert ]
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a better idea about it all now. Thanks maates!!
Lupo
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!