1 4 package org.oddjob.devguide; 5 6 public class SimpleService { 7 8 private Thread t; 9 10 public void start() { 11 12 t = new Thread (new Runnable () { 13 public void run() { 14 while (true) { 15 System.out.println("I could be useful."); 16 synchronized (this) { 17 try { 18 wait(5000); 19 } catch (InterruptedException e) { 20 System.out.println("OK - I'll stop."); 21 break; 22 } 23 } 24 } 25 }}); 26 t.start(); 27 } 28 29 public void stop() { 30 t.interrupt(); 31 } 32 } 33 | Popular Tags |