Saral Saxena

Ranch Hand
+ Follow
since Apr 22, 2011
Saral likes ...
Eclipse IDE Oracle Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Saral Saxena

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!
Done!



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, ..!!