---
title: "Daemon Thread Notes"
author: "willpower"
date: "2007-04-03T09:16:22Z"
tags: []
slug: "daemon-thread-notes"
draft: false
lastmod: "2007-04-03T09:16:22Z"
id: 67529
url: "https://willpower.iteye.com/blog/67529"
---

1\. 只要程式中的non-Daemon thread都結束了..  
就算有Daemon Thread仍在執行中...  
程式一樣會被強制結束...

最簡單的例子就是garbage collector thread..

2\. 如果某個 Thread 是 daemon thread，則它所產生的所有 threads 天生就  
具有 daemon 的特性

3\. A daemon thread should be used for some background task that  
might provide a service to the applications. e.g. a Server thread  
listening on a port for the clients' requests.  
出自[http://www.vyomworld.com/source/show.asp?ScriptID=176](http://www.vyomworld.com/source/show.asp?ScriptID=176)

以下出自[http://web.syr.edu/~maaljlay/daemon.html](http://web.syr.edu/~maaljlay/daemon.html)  
4\. Any Java thread can be a daemon thread. Daemon threads are service  
providers for other threads or objects running in the same process as  
the daemon thread. For example, the thread that runs the garbage  
collector in Java is a daemon thread, In general, threads that run  
application code are not daemon thread, and threads that run system  
code are daemon threads

5\. The run() method for a daemon thread is typically an infinite loop that  
waits for a service request, perform the service, and wait for the next  
service request. Daemon threads continue to execute until there are  
no more threads for which services can be provided. At this time, the  
daemon threads die and the java interpreter terminated its execution.

6\. Daemon threads are typically independent threads within an application  
that provide services for other objects within that same application

7\. As result from the experiment, the daemon threads are equal in  
priority of the conventional user threads, it is recommended to make  
them in the lowest priority as the garbage collector thread in java.