• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is Demon thread and what is Green thread

 
Dhineshkumar raj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) What is Demon thread?

2) what is Green thread?

Can you one example for demon thread.

Regards
Dhinesh
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the actual word is daemon thread but, they are sometimes referred as demon thread as they just keep on running and haunt you back

A daemon thread is a thread that exists/runs in the background. It basically is a low priority thread.
The use of daemon thread is that JVM exits when the last running thread finishes. In a GUI this typically happens when the last window is closed (which ends the dispatcher thread).If you set a Thread to daemon status then that thread doesn't prevent the JVM from exiting if it's still running.So it's used for background threads. Typically these threads speand most of their time waiting for some condition to arise which they then quietly handle. They might be waiting for an incoming socket connection. They might wake up every five minutes and check that a file hasn't been updated. They might be waiting for some task to be added to a queue which they then execute. etc. etc.

You can refer this link for more info.


A green threads is a thread that is scheduled by a JVM itself.
Wikipedia has a good description. Refer this link.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anubhav Anand:
A daemon thread is a thread that exists/runs in the background. It basically is a low priority thread.


Not true. Daemon threads have no difference in priority to ordinary threads. You can set a daemon thread to low priority, just as you can set an ordinary thread to low priority.

The only difference between daemon threads and ordinary threads is that daemon threads are not included in the JVM's decision of when to exit.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It basically is a low priority thread.


I didn't assert it , rather I told usually they are low priority( whch obviously can be altered).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!