Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait and notify method method

 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait and notify notifyall method are basically used are basically used in threads so why they are included in Object class and not in thread class
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads synchronize on objects, and those methods are related to the object you're synchronizing on, not the thread that's doing the synchronizing.
 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir can you please example in details
 
Henry Wong
author
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deepak carter wrote:wait and notify notifyall method are basically used are basically used in threads so why they are included in Object class and not in thread class


deepak carter wrote:sir can you please example in details



Please do a search for this (SearchFirst), as this question comes up often....

http://www.coderanch.com/t/233340/threads/java/Why-java-lang-Object

Henry
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deepak carter wrote:wait and notify notifyall method are basically used are basically used in threads so why they are included in Object class and not in thread class


Because wait() and notify() apply to locks and every object has a lock.

Also, everything in Java is "used in threads."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic