• 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

threads initiating threads

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This was a question someone asked me at an interview.
If hread A initiates Thread B and Thread B in turn initiates Thread C,
what happens to Thread B and C if thread A gets killed

Someone please tell me how i can test this out in code... How do i kill a thread A befor it get's executed completely?
Also, while you are at it... please tell me what a deamon thread exactly means.

Thanks
 
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
Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name here. Thanks!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
even if the thread A gets killed the program continues to run until thread b & c finish exection (exception to this case i.e program terminates if the thread B & C are deamon threads)
 
Abhishek Iyer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay thanks... but what exactly is a deamon thread?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JVM continues to run until all normal threads of your application stop. A daemon thread is a thread that doesn't keep the JVM running; if all normal threads have stopped but there are still daemon threads running, then the JVM exits anyway.

You can make a daemon thread by calling setDaemon(true) on the Thread object.

(Note, it's daemon, not deamon).
[ August 20, 2007: Message edited by: Jesper Young ]
 
Awishek sinha
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
daemon threads are something thats runs in background similar to some of the services of OS
 
Abhishek Iyer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Awishek and Jesper... one quick thing though... Why would you want to make a thread daemon? What purpose does that serve... If the JVM exits... the daemon thread will alo get killed right?
 
Awishek sinha
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Abhishek Iyer:
Thanks Awishek and Jesper... one quick thing though... Why would you want to make a thread daemon? What purpose does that serve... If the JVM exits... the daemon thread will alo get killed right?



daemon thread say if we want to monitor few activities of the main thread we have a daemon thread perform the monitoring but there is no use of this thread when main thread exit so the jvm exit & kills the daemon thread when main thread finishes execution.
 
reply
    Bookmark Topic Watch Topic
  • New Topic