From the course: Java Threads

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Daemon vs. non-daemon threads

Daemon vs. non-daemon threads - Java Tutorial

From the course: Java Threads

Daemon vs. non-daemon threads

- [Instructor] There are two kinds of threads, daemon threads and non-daemon or user threads. A daemon thread can be thought of as an infrastructure thread that runs in the background to perform tasks like garbage collection or GUI event dispatching. The Java Garbage Collector thread and Swing Event Dispatcher thread are great examples of daemon threads. A non-daemon or user thread is any thread that isn't an infrastructure thread. It can perform any program task that you define. The main thread that you saw earlier is also a non-daemon thread. Any newly created thread inherits the daemon status, that is, whether it's a daemon or non-daemon thread, from its parent thread. That's why all threads created inside the main method, in other words, child threads of the main thread, are non-daemon by default. You can make a user thread or a non-daemon thread daemon using the setDaemon method of the thread class. To do that…

Contents