
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What method is used to create a daemon thread in Java?
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
import java.lang.*; class adminThread extends Thread { adminThread() { setDaemon(false); } public void run() { boolean d = isDaemon(); System.out.println("daemon = " + d); } } public class ThreadDemo { 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 Questions & Answers
- What is a daemon thread in Java?
- Daemon thread in Java
- User Thread vs Daemon Thread in Java?
- How to get current thread is daemon in android?
- How to create a thread using method reference in Java?
- How to create a thread in Java
- What is the Thread class in Java?
- How to create a thread in JShell in Java 9?
- How to create a thread using lambda expressions in Java?
- How to create a thread in C#?
- How to create a thread in android?
- What is Thread cancellation?
- How to create a thread by using anonymous class in Java?
- What are the ways in which a thread is created in Java?
- C# Program to create a Simple Thread
Advertisements