daemon thread

At what purpose we go for daemon thread?

could you give me Examples?
LVL 9
Manikandan ThiagarajanSenior consultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.