• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ait and notify again

 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a better idea about it all now. Thanks maates!!
Lupo
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic