• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

daemon thread

At what purpose we go for daemon thread?

could you give me Examples?
Manikandan Thiagarajan
Manikandan Thiagarajan
3 Solutions
A deamon thread cycles until the application exits.

You don't have to kill a deamon thread.
A counter example: as soon as you got a GUI, you got a non-daemon thread.
Your 'main' thread may finish, you got to close your Frame or the application will stay.

Daemon thread are threads that are not vital for the running of the application, thus even if a daemon thread is running the JVM can exit if no other non-daemon threads are running.

For example u created a frame that shows the status of a website www.xyz.com. So for this what u r doing is connecting to the site and if gets a reply shows a message that the site is fine. So to connect to the site u have created a Daemon Thread using:-
Thread thread=new Thread();

No if some exceptions occurs in the Main thread which is running the GUI or if u want to close the Frame u can do so without considering for the daemon thread as the JVM exits if no non-daemon threads are running.
look at this link:-
Mayank SAssociate Director - Product EngineeringCommented:
Basically its like a background thread which you can use for doing some processing as long as the application is running. The main thread can exit regardless of this thread, and if it does the daemon thread will exit too allowing the application to gracefully close. Otherwise you will run into problems if the main thread exits but there are other non-daemon threads active as that will not allow the application to gracefully shut down.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now