Core Java Tutorials


Introduction

Java Hello World

Java Compilation

JDK New Features

JVM Architecture

Java OOPs Concepts

Java Package

Array

Exception Handling

String

Immutable Class

File Handling

Serialization

MultiThreading

Volatile

Concurrent Package

Collection

Collection Internal

Generics

Cloning

Reflection In Java

Annotation

Class Loader

Java Inner classes

Garbage Collector

JDBC

References In Java

Heap Dump & Thread Dump

Deamon Thread:-


When an application begins running, there is one non-daemon thread, whose job is to execute main().
Correct. The JVM exits when the last non-daemon thread exits. If the main thread wasn't non-daemon then the JVM would start up and see that there were no non-daemon threads running and would shutdown immediately.


 Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.


Creating deamon thread:-

Agile agile=new Agile();
Thread t=new Thread(agile);
t.setName("AKT");
t.setDaemon(true); //making thread as a daemon
t.start();


Creating non deamon thread:-

Agile agile=new Agile();
Thread t=new Thread(agile);
t.setName("APK");
t.setDaemon(false); //making thread as a non daemon
t.start();

 if parent thread creates two children threads which are non daemon then parent thread can not terminate unless it's both children finish it's execution.