Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

notify() in threads

 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Here is a Q from a mock exam
Which of the following are true.
1) notify() is in Thread class.
2) notify() is a synchronized method.
3) notify() puts a thread from lock state to waiting .
OF these which are true. I know that notify(), notifyall() and wait() are the methods of Object class. Also notify() is a native method.
Can any body please give an answer for this.
Thanks in advance.
 
Wong KK
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) notify() is in Thread class.
2) notify() is a synchronized method.
3) notify() puts a thread from lock state to waiting .
None of them is true.
notify() is a method defined in Object. (Although you may argue that Thread has inherited this method)
notify is not a synchronized method. (It just must be run in a synchronized method)
notify puts a thread from waiting to ready. (If it can acquire the lock, else it will go to block state)
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi wong,
Thankyou very much. Can you please clear one more .
The methods of thread class are run(), start() ,getpriority()
right.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the API for all the methods of the thread class. The ones you mentioned are methods of the thread class but there are a whole lot more methods also.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic