KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > devguide > SimpleService


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.devguide;
5
6 public class SimpleService {
7
8     private Thread JavaDoc t;
9
10     public void start() {
11         
12         t = new Thread JavaDoc(new Runnable JavaDoc() {
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 JavaDoc 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