What is Daemon thread in java

Total Post:46

Points:324
Java  Thread 
 1268  View(s)
Ratings:
Rate this:
I am very much confused about daemon threads, can anyone tell me what is daemon threads and why we use them?
  1. Post:397

    Points:3117
    Re: What is Daemon thread in java

    A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection.

    You can use the setDaemon() method to change the Thread daemon properties.When a new thread is created it inherits the daemon status of its parent.
    Normal thread and daemon threads differ in what happens when they exit. When the JVM halts any remaining daemon threads are abandoned:

    finally blocks are not executed,
    stacks are not unwound - the JVM just exits.

    Due to this reason daemon threads should be used sparingly and it is dangerous to use them for tasks that might perform any sort of I/O.

      Modified On Apr-10-2018 02:33:15 AM

Answer