This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread

 
Lalit G
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
Can anybody pls tell me the difference between daemon and user threads?
How daemon thread is useful during execution of prog.
What's the priority of daemon thread?
Does it belongs to ThreadGroup?
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a daemon thread is generally a thread running in the background. The threads you create in a program are user threads unless you specify otherwise. I'm not sure the priority of a daemon thread. If there is one, I'd imagine it's pretty low.
 
sharad goswami
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
THE DAEMON THREAD IS THREAD RUNNING IN THE BACKGROUNG BY JAVA VITUAL MACHINE.FOR EXAMPLE GARBAGE COLLECTION IS RUN BY LOW PRIORITY DAEMON THREAD OF JVM.
 
Yuri Gadow
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daemon threads will not prevent the VM from exiting. Once all work in non-daemon threads is complete (the runs have returned), the VM will exit - so a daemon thread is most suitable for continuous tasks that support primary functions (like GC, lock sweeping, connection time-outs, etc.)
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The daemon thread, except that it is managed by JVM and will get killed if no user threads are running, is also just another thread. Therefore, just like normal threads, they will have the priority of the creating thread and the value Thread.NORM_PRIORITY by default. They will belong to the same ThreadGroup as their parent thread, unless explicitly created as belonging to another ThreadGroup using the overloaded Thread constructor. Infact you can set the entire ThreadGroup as daemon. Any threads that belong to that ThreadGroup will be marked as daemon too.

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic