A thread is non-daemon by default, and setDaemon(true) must be called before start(). Daemon status only affects whether the JVM waits for the thread on exit; it does not change how the thread runs.
Thread worker = new Thread(() -> { });
System.out.println("Default daemon flag: " + worker.isDaemon());
worker.setDaemon(true);
System.out.println("After setDaemon(true): " + worker.isDaemon());
worker.start();
worker.join();
System.out.println("Daemon thread finished normally");
Default daemon flag: false
After setDaemon(true): true
Daemon thread finished normally
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27