• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Another JQ+ Thread

 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID :952739431260
Which of the following is true?
1:A program ends when all daemon threads end
2:A program ends when all non-daemon threads ends
3:A daemon thread is a low priority thread that never stops but keeps running in the back ground
4:A user thread cannot stop the non-user or daemon thread.
Correct Ans:2
JQ+ Explanation:
Daemon threads are meant to perform supporting tasks that make sense only if normal threads are running.
For eg. the Garbage Collecter thread is usefull only if some user thread is running. If all the user threads end then what is the use of GC thread? So the program should end when all the non-daemon threads end.
You can make any Thread (if you have permission) a daemon thread by calling setDaemon(true);
You can stop any thread.
**************************************************************
It says that What is the use of GC thread if all the user threads ends.If there is no use then who will GC the user threads which has died?
A/C to me option 3 is correct.
Bye
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the test although not sure about their wording
2. Is correct because when all non-deamon threads finish the program ends. A deamon thread comes to an end when the thread that created it ends, if all non-deamon threads have finished it implies the thread that created it has finished (might go through other deamon threads but eventually will get to a non-deamon thread). However it might not appear to occur immediately due to switching between threads
3. Is incorrect as a deamon thread is still a thread, it may naturally come to an end itself or be interrupted just like any other thread, it does not need to be a continuous loop. In fact thinking about it, it automatically comes to an end when the thread that created it comes to an end which could happen at any time.
Phil
 
Vikrama Sanjeeva
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Phil try to understand my question.


It says that What is the use of GC thread if all the user threads ends.If there is no use then who will GC the user threads which has died?


Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic