Results 1 to 3 of 3
- 04-22-2011, 02:41 PM #1Member
- Join Date
- Feb 2011
- Rep Power
Why wait(), notify(), notifyAll() declared in Object class?
why is it that wait(), notify(), notifyAll() methods have been declared in the Object class and not in the Thread class? Is it possible to call these methods on the main thread?
If we create a thread by a Runnable instance, then how could we access the methods of the Thread class?? can we import java.lang.Thread?
- 04-22-2011, 03:11 PM #2
It's because you can use any Object as a lock. These functions would actually be pretty useless if they were only in the Thread class.
For example, say you have an Object and two methods that do different things with that Object. Many different Threads are accessing those two methods, but you want to synchronize those methods. How would you do that if wait(), notify(), etc were only in the Thread class?
As for the rest of your questions, what happened when you tried?
- 04-24-2011, 12:46 AM #3
- By jomypgeorge in forum New To JavaReplies: 4Last Post: 02-15-2011, 08:58 AM
- By mityay in forum Threads and SynchronizationReplies: 3Last Post: 01-06-2011, 04:24 PM
- By cuffJ in forum Threads and SynchronizationReplies: 6Last Post: 08-18-2010, 03:21 AM
- By Mkaveli in forum Threads and SynchronizationReplies: 2Last Post: 03-30-2010, 11:58 AM
- By denis in forum Threads and SynchronizationReplies: 13Last Post: 04-22-2009, 08:28 AM