[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

daemon thread

At what purpose we go for daemon thread?

could you give me Examples?
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
3 Solutions
 
sciuriwareCommented:
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.

;JOOP!
0
 
gauravkrtomarCommented:
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();
thread.setDaemon(true);

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:-
http://www.cafeaulait.org/course/week11/28.html
0
 
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.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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