Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about daemon thread AND JVM

 
david hu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's sait that the Java Virtual Machine exits when the only threads running are all daemon threads. If the JVM exits, who is reponsible to interpret the bytecode of the daemon thread, how can these deamon thread continues running?
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by david hu:
If the JVM exits ... how can these deamon thread continues running?

They dont. Once the JVM exits all of the daemon threads are killed and stop running.
 
kumar bangali
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW What is a Daemon thread? Is it some kind of System Thread used by the JVM only?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The previous posts have given the definition of a daemon thread. They are used to perfomance maintining task that are not the main objective of a program, but are needed for its success.
 
sun ram
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
User also can create daemon thread, before starting the Thread we need to call setdaemon method with true value. If parent thread exits, deamon child threads also exit automatically.
this is how we create deamon thread.

PrimeRun p = new PrimeRun(143);
Thread t = new Thread(p);
t.setDeamon( true );
t.start();
-SR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic