• Post Reply Bookmark Topic Watch Topic
  • New Topic

join() and wait method  RSS feed

 
srikant nair
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please explain the difference between join() and wait method with a simple example
 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
join() blocks until the thread you call it on terminates. wait() blocks until another thread calls the notify() or notifyAll() method of the object you called wait() on.

In general, join() is used when you've splitten some task in parts to be handled by separate threads concurrently, after which you want to wait until they've all completed. wait() can be used to block until some condition holds true, regardless of whether another thread terminated.

In modern code, you have almost no reason to use these methods. Instead, you should use the high level concurrency classes from the java.util.concurrent packages.
 
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!