• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Thread

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between Daemon Thread and Non Daemon.Can you please some example.

Thanks
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are daemon threads and user threads.

When the "main()" method is finished, it can happen that other threads are still running (i.e. not finished their "run()" method). It is easy to think of examples.

If the "main()" method is finished, but other user threads are still runnning, the JVM keeps running until the last user thread is finished running.


If the "main()" method and ALL user threads are finished, but there are still daemon threads running, the JVM stops running. In this case, it terminates the "run()" method(s) of the daemon thread(s) before it/they finish.

This is the only difference. It is just a way to mark a thread as "must finish" (user) or "doesn't have to finish" (daemon).

Often daemon threads are "helper threads" and run in an infinite loop "for( ; ; ) { //code }, so they can never finish their "run()" method. As a daemon thread, an infinite loop is OK, since the thread will end anyway when all user threads are finished.

Do you understand now?
[ July 24, 2006: Message edited by: Douglas Chorpita ]
 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply but i want some programs.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I create a daemon thread?
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic