Java Multithreading Tutorial for Beginners #11: Daemon Threads

preview_player
Показать описание
In this chapter, we will talk about Daemon threads in Java. When a normal thread is running in background, it does not allow the JVM to exit until that thread is complete. A daemon thread is a thread that does not prevent the JVM from exiting when the program finishes but the thread is still running.

You can find the source code of this chapter in the following GitHub repository.

Website:-

#Multithreading
#GenuineCoder
#Java
Рекомендации по теме
Комментарии
Автор

I have some notes for who needs:

Java offer 2 types of thread: *user thread* and *daemon thread.*
All of the threads we used in the previous chapters are user threads.
User threads are high-priority threads. The JVM will wait for any user thread to complete its task before terminating it.

So what is daemon thread?
Daemon threads are *low-priority* threads that *does not prevent JVM from exiting* when the program finishes but the thread
is still running. In other words, The JVM exits when the only threads running are all daemon threads.
For example: a daemon thread is the garbage collection.

* Note:
1. Daemon threads are not recommended for *I/O tasks*
2. Do not call *join()* method for daemon threads

lzZxxZzl
visit shbcf.ru