1 package org.tanukisoftware.wrapper.test; 2 3 45 46 import org.tanukisoftware.wrapper.WrapperManager; 47 48 53 public class LongRunningBackgroundThreads implements Runnable { 54 private volatile int _threadCount; 55 56 59 public void run() { 60 ++_threadCount; 61 int loops = 0; 62 63 while(loops < 10) { 64 loops++; 65 System.out.println(Thread.currentThread().getName() + " loop #" + loops); 66 try { 67 Thread.sleep(500); 68 } catch (InterruptedException e) { 69 } 70 } 71 System.out.println(Thread.currentThread().getName() + " stopping."); 72 if(--_threadCount <= 0){ 73 System.out.println("The JVM and then the wrapper should exit now."); 74 } 75 } 76 77 80 public static void main(String [] args) { 81 System.out.println("Long-running Background Threads Running..."); 82 83 LongRunningBackgroundThreads app = new LongRunningBackgroundThreads(); 84 for (int i = 0; i < 2; i++) { 85 Thread thread = new Thread (app, "App-Thread-" + i); 86 thread.start(); 87 } 88 89 System.out.println("Running as a service: " + WrapperManager.isLaunchedAsService()); 90 System.out.println("Controlled by wrapper: " + WrapperManager.isControlledByNativeWrapper()); 91 92 System.out.println("Long-running Background Threads Main Done..."); 93 } 94 } 95 | Popular Tags |