• Post Reply Bookmark Topic Watch Topic
  • New Topic

Daemon threads and join()  RSS feed

 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody explain what are deamon threads and where can i find
some notes on join().
Thanku,
MAdhuri.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally, the JVM stops when all of your Threads have finished. But sometimes you need to create a Thread which performs some background service, indefinitely. When your main thread exits, you want the JVM to stop too, even though this background thread may still be running. By creating it as a daemon thread, you are telling the JVM that it should not wait for it to die.
You can find a brief description of Thread.join in the javadoc. I don't know if Sun has a more elaborate description elsewhere, but what it boils down to is this.
Say you have a thread A. It needs to gets some slow I/O bound work done (e.g. retrieve a web page, load a file) which is most effectively done in a separate thread. So it spawns a thread B to do this, and continues with its work.
Sometime later, A needs to do something which can only be done if B has finished its work. That's where join() kicks in:

Hope this clarifies how join() is used.
- Peter

[This message has been edited by Peter den Haan (edited May 10, 2001).]
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you .Please give a reply to my previous Q on threads.
Madhuri.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!