---
title: "Daemon Thread in Java"  
description: "In java, Damon thread is a low priority thread .It is used for providing background support to any user thread to same process as the daemon thread."  
author: "Anupam Mishra"  
published: 2015-12-10  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/11939/daemon-thread-in-java  
category: "java"  
tags: ["java", "thread", "threading", "thread abort", "j2ee"]  
reading_time: 2 minutes  

---

# Daemon Thread in Java

In java, Damon thread is a low priority thread .It is used for providing background [support](https://yourviews.mindstick.com/view/81072/pakistan-wants-enmity-not-support-from-india-during-coronavirus-pandemic) to any [user thread](https://www.mindstick.com/forum/159080/explain-about-the-relationship-between-a-kernel-and-a-user-thread) to same [process](https://www.mindstick.com/forum/23018/how-can-i-create-a-process) as the daemon thread. If you want to make any user [threads](https://answers.mindstick.com/qa/106080/how-to-use-twitter-threads-for-comprehensive-storytelling) to as a [daemon thread](https://www.mindstick.com/interview/1481/what-is-a-daemon-thread) then it must not be started otherwise, [throw exception](https://www.mindstick.com/forum/33937/difference-between-throw-exception-and-throw-clause). Its life or role depends upon user level threads.

Daemon thread is very useful for the [background tasks](https://www.mindstick.com/forum/158891/how-can-you-handle-background-tasks-in-android) and only needed while normal thread are executing and normal thread are set as a daemon thread. For setting a user thread to a daemon thread, we using a setDaemon (boolean status) method to user level thread.

For checking current thread is a daemon or not, we using Thread.currentThread().isDaemon() method that returns [true or false](https://www.mindstick.com/forum/160329/how-can-you-convert-a-value-to-a-boolean-true-or-false-in-javascript).

If any user thread are not running then JVM terminates the daemon thread automatically.

For Example, we have taken 3 threads t1, t2 and t3 respectively and before [starting](https://www.mindstick.com/blog/12024/things-you-need-to-know-when-starting-your-own-business) thread t1 we set as Daemon to thread t1.

```
public class DaemonThread extends Thread{
public void run(){
if(Thread.currentThread().isDaemon()){
       System.out.println("Daemon Thread Is  Working");
  }
  else{
       System.out.println("User Thread is Running ");
 }
 }
 public static void main(String[] args){
   DaemonThread t1=new DaemonThread();
 DaemonThread t2=new DaemonThread();
   DaemonThread t3=new DaemonThread();
    t1.setDaemon(true); //now t1 is daemon thread
    t1.start();//starting threads
    t2.start();
    t3.start();
 }
}  
```

## \

![Daemon Thread in Java](https://www.mindstick.com/mindstickarticle/0cea1665-d790-4339-b810-dfc65662ec04/images/c68f0141-e20a-45fc-9322-4bcf95611276.png)

---

Original Source: https://www.mindstick.com/articles/11939/daemon-thread-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
