Java Multithreading Tutorial for Beginners #11: Daemon Threads
HTML-код
- Опубликовано: 22 мар 2019
- 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 set a thread as daemon thread using java.lang.Thread#setDaemon(boolean) function.
You can find the source code of this chapter in the following GitHub repository.
github.com/afsalashyana/Java-...
Website:-
www.genuinecoder.com
#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
tbh, this comments explains more than the vid