daemon thread

Posted on 2006-04-18
Last Modified: 2012-06-22
At what purpose we go for daemon thread?

could you give me Examples?
Question by:stmani2005
    LVL 24

    Accepted Solution

    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.

    LVL 2

    Assisted Solution

    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 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:-
    LVL 30

    Assisted Solution

    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.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    fetching the full url inside controller 2 31
    scoresClump  challenge 31 88
    wordsWithout 49 64
    How Complex Is This Java Course ? 9 52
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This video teaches viewers about errors in exception handling.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now