• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deamon Thread Sample

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Examine code below:

When I set t1.setDaemon(true) the following output is produce....

....and when I set t1.setDaemon(true) and t2.setDaemon(true)the following output is produce:

I'm expecting that when you set t1 as a daemon thread it should be stop executing when the main thread dies. Why does daemon thread t1 still execute when its parent thread main thread is already
in a dead state?
 
Richard Teston
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it!, daemon thread still executes when there is still at least one user thread executing in my code case when i set t1.setDaemon(true) I have t1 as a daemon thread and my t2 and main thread are my user thread. When main thread stop executing, t1(daemon thread) will continue to execute because t2(user thread) is still alive. When i set t1 and t2 as a daemon thread their lives is in the hand of main(user thread), so when main thread stop executing t1 and t2 (daemon thread) will also stop executing. em I making any sense?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you're making sense. There's nothing special about the main thread. In many graphical programs, the main thread exits as soon as it set up the GUI; the GUI event thread, a non-daemon thread, keeps the application running.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic