File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes java biginer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "java biginer" Watch "java biginer" New topic

java biginer

ash sangy

Joined: Jul 09, 2011
Posts: 6

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

Joined: Jun 15, 2010
Posts: 238

call notify() method from thread object which you are using at the time of wait() method call.

SCJP 6- 91%, IBM DB2, IBM RAD Certified
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46393
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

Joined: Mar 18, 2011
Posts: 312

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().

Not many get the right opportunity !
I agree. Here's the link:
subject: java biginer
It's not a secret anymore!