• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

join() and wait method  RSS feed

 
Ranch Hand
Posts: 30
  • 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
 
Bartender
Posts: 9488
184
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!