Online Java Compiler By
JavaTpoint.com
public class JavaIsDaemonExp extends Thread { public void run() { //checking for daemon thread if(Thread.currentThread().isDaemon()) { System.out.println("daemon thread work"); } else { System.out.println("user thread work"); } } public static void main(String[] args) { // creating three threads JavaIsDaemonExp t1=new JavaIsDaemonExp(); JavaIsDaemonExp t2=new JavaIsDaemonExp(); JavaIsDaemonExp t3=new JavaIsDaemonExp(); // set user thread t1 to daemon thread t1.setDaemon(true); //starting all the threads t1.start(); t2.start(); t3.start(); } }
Output