Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Q from Khalid Q.44

 
Brian, Cavanagh
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another one, which caused similar problems guys?
Which statements concerning the methods notify() and notifyAll() are true?
1. Instances of class Thread have a method called notify()
2. A call to the method notify() will wake the thread that currently own the monitor of the object.
3. The method notify() is synchronized
4. The method notifyall() is defined in class Thread
5. When there is more than one thread waiting to obtain the monitor of an object, there is no way to be sure which thread will be notified by the notify() method.
I know 3. False
4. False
But, I would be interested to hear what you guys think of the other options.
Cheers,
Brian
 
Brian, Cavanagh
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's ok guys I got it.
1, 5 are true.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why 1 is correct?
I think instances of class Object have a method called notify()
please someone verify this.
 
Yamuna Pattathil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread class inherits the method from Object class. So 1 is also correct
[This message has been edited by Yamuna Pattathil (edited December 12, 2000).]
 
Michael Burke
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd agree with Nasir #1 is false.
 
Brian, Cavanagh
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread (like all objects) extends from Object, and therefore each instance has a notify(), wait() and notifyAll() method, as do any other object.
Look at this code:
String s = new String();
s.wait();
is completely valid.
 
Neha Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Brain.
Answer 1 is correct.
Notify and NotifyAll are public methods and subclasses inherit from super.So 1 is correct.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No 1 is correct in a sense that Thread extends Object.
I was confused because of the way wait() and notify() are used I mean they are used like object instance method ,not
like thread instance method.I'll be thankful if someone give more explaination on that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic