Back-End/Java_1

[Java] Daemon Thread

리딩리드 2016. 10. 10. 15:27

Daemon Thread

- Daemon Thread is a service provider thread that provides services to the user thread

- Its life depend on the mercy of user thread i.e. all the user threads dies, JVM terminates this thread automatically

- gc, finalizer etc..


1. Points to remember for Daemon Thread

- It provides services to user threads for background supporting tasks

- Its life depends on user thread

- It is a low priority thread

2. Why JVM terminates the daemon thread if there is no user thread?

- The sole purpose of the daemon thread is that it provides services to user thread for background supporting task

- If there is no user thread, we don't need daemon threads

3. Methods for Daemon thread by Thread class

1) public void setDaemon(boolean status)

- It is used to mark the current thread as daemon thread or user thread

2) public boolean isDaemon()

- It is used to check that current is daemon

4. Example