Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java biginer

 
ash sangy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have a doubt in core java multithreading i have to invoke waited threads (assume 10 threads are waiting state) how can we cal only one particular waiting thread using notify()?
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
call notify() method from thread object which you are using at the time of wait() method call.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can call a particular thread like that. If you call notify(), you call one thread, selected non-deterministically. If you call notifyAll() you can wake any because all threads are notified.

I think this question too difficult for "beginning" so I shall move it.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have volatile boolean variables for each Thread and set to true the one for the required Thread. Within the Thread check if its volatile variable is set to true, if so do the needful, if not go back to sleep. Call notifyAll().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic