1 package org.tanukisoftware.wrapper.test; 2 3 45 46 51 public class BackgroundThreads 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("Background Thread Test Running..."); 73 System.out.println("Launching background non-daemon threads..."); 74 75 BackgroundThreads app = new BackgroundThreads(); 76 for (int i = 0; i < 2; i++) { 77 Thread thread = new Thread (app, "App-Thread-" + i); 78 thread.start(); 79 } 80 81 while ( !m_started ) 85 { 86 try 87 { 88 Thread.sleep( 10 ); 89 } 90 catch ( InterruptedException e ) 91 { 92 } 94 } 95 96 System.out.println("The JVM should now continue to run indefinitely."); 97 98 System.out.println("Background Thread Test Main Done..."); 99 } 100 } 101 102 | Popular Tags |