Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

join() and wait method  RSS feed

 
Greenhorn
Posts: 27
  • 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
 
Saloon Keeper
Posts: 9126
172
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!