- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Daemon thread in Java
A Daemon thread is a background service thread which runs as a low priority thread and performs background operations like garbage collection. JVM exits if only daemon threads are remaining.
The setDaemon() method of the Thread class is used to mark/set a particular thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads. This method must be called before the thread is started.
Example
class adminThread extends Thread { adminThread() { setDaemon(false); } public void run() { boolean d = isDaemon(); System.out.println("daemon = " + d); } } public class Tester { public static void main(String[] args) throws Exception { Thread thread = new adminThread(); System.out.println("thread = " + thread.currentThread()); thread.setDaemon(false); thread.start(); } }
Output
thread = Thread[main,5,main] daemon = false
- Related Articles
- User Thread vs Daemon Thread in Java?
- What is a daemon thread in Java?
- What method is used to create a daemon thread in Java?
- How to get current thread is daemon in android?
- Difference Between Daemon Threads and User Threads In Java
- Thread Pools in Java
- How a thread can interrupt another thread in Java?
- Inter thread communication in Java
- Get current thread in Java
- Demonstrate thread priorities in Java
- Change Thread Priority in Java
- Naming a thread in Java
- Java Thread Priority in Multithreading
- Thread Interference Error in Java
- Is Java matcher thread safe in Java?

Advertisements