• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why wait() Method is in Object class  RSS feed

 
Ravi Sinha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There!
Can anybudy expalin me why wait () Method is in Java Object calls...whats its purpus & use
ravi
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that any object can be used as a synchronization lock, considering that all objects in Java are inherited from Object. Note also that notify and notifyAll are also defined there for the same reason.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java virtual machine can execute multiple threads concurrently. A thread is a path of execution in a Java program.
Sometimes one thread must wait for some condition to exist before it continues to execute. Another thread does something to cause the condition to exist. Then it notifies the first thread.

An object has a wait set. When a thread invokes wait() on the object, the thread is added to the object's wait set. When another thread invokes notify() on the object, a thread is removed from the object's wait set.
[ January 03, 2004: Message edited by: Marlene Miller ]
 
Ravi Sinha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for giving reply..........still i want to know is there any role of garbage collector gc() over here.....
once again thanks
Bye
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!