1 package org.tanukisoftware.wrapper.test; 2 3 45 46 51 public class DaemonThreads implements Runnable { 52 private static boolean m_started = false; 53 54 57 public void run() { 58 m_started = true; 59 while(true) { 60 System.out.println(Thread.currentThread().getName() + " running..."); 61 try { 62 Thread.sleep(500); 63 } catch (InterruptedException e) { 64 } 65 } 66 } 67 68 71 public static void main(String [] args) { 72 System.out.println("Daemon Thread Test Running..."); 73 System.out.println("Launching background daemon threads..."); 74 75 DaemonThreads app = new DaemonThreads(); 76 for (int i = 0; i < 2; i++) { 77 Thread thread = new Thread (app, "App-Thread-" + i); 78 thread.setDaemon(true); 79 thread.start(); 80 } 81 82 while ( !m_started ) 86 { 87 try 88 { 89 Thread.sleep( 10 ); 90 } 91 catch ( InterruptedException e ) 92 { 93 } 95 } 96 97 System.out.println("The JVM should exit momentarily."); 98 99 System.out.println("Daemon Thread Test Main Done..."); 100 } 101 } 102 103 | Popular Tags |