Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Regarding Notify  RSS feed

Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks..

I was going through threads and I read that ..The notify() method is used to send a signal to one and only one of the threads that are waiting in that same object's waiting pool. The method notifyAll() works in the same way as notify(), only it sends the signal to all of the threads waiting on the object....Now my query is that if Lets say I have 5 threads waiting and through Notify() , i want to send to notification to thread 3 only, what logic should be there that notification is sent to thread 3 only ..!!

I have come up with the code..

The ouput will be...

Thread-0 going to wait...
Thread-3 going to wait...
Thread-2 going to wait...
Thread-4 going to wait...
Thread-1 going to wait...
Thread-2 woken up!

So you can clearly see that only the third thread (indexed from zero) is woken up.

But please advise me any simpler code to achieve the same thing as this code is still not clear to me, ..!!
Posts: 4179
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simpler code would include the use of Locks and Conditions, rather than Object.wait() and Object.notify(). See The High Level Concurrency Tutorial for info on how to use them. Pseudo-codish example might be:

Whatever you say buddy! And I believe this tiny ad too:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!