WHAT IS DAEMON THREAD IN JAVA

sandy taylor

Total Post:46

Points:324
Posted by  sandy taylor
Java  Thread 
 896  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. Mayank Tripathi

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!