The Java Program: Daemon.java

  1 import java.lang.Thread;
  2 
  3 class Daemon extends Thread {
  4 
  5    public void run () {
  6       while (true) System.out.print ("Ha");
  7    }
  8 
  9    public static void main (String[] args) throws InterruptedException {
 10       Thread d = new Daemon();
 11 
 12       /*
 13          Marking a "Thread" as a daemon thread means that it should
 14          automatically be killed when no other (non-daemon) application
 15          thread remains to be executed.
 16       */
 17       d.setDaemon (Boolean.valueOf (args[0]).booleanValue());
 18 
 19       d.start ();
 20 
 21       Thread.sleep (1000);
 22    }
 23 
 24 }