KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > util > scheduler > SchedulerThread


1 package de.webman.util.scheduler;
2
3 import org.apache.log4j.Category;
4
5
6 /**
7  * The scheduler master thread which checks for scheduler service to kick
8  * off. Should be a private or package class inside SchedulerMgr, but this
9  * is not allowed by JTest. So its here.
10  *
11  * @author <a HREF="mailto:gregor.klinke@webman.de">Gregor Klinke</a>
12  * @version $Revision: 1.2 $
13  **/

14 public class SchedulerThread
15     implements Runnable JavaDoc
16 {
17     /* $Id: SchedulerThread.java,v 1.2 2002/04/12 12:45:53 gregor Exp $ */
18     /**
19      * the logging facility
20      **/

21     private static Category cat = Category.getInstance(SchedulerThread.class);
22
23     /**
24      * the parent ScheduleMgr
25      **/

26     private SchedulerMgr mgr;
27     
28     /**
29      * is this thread finished
30      **/

31     private boolean finished = false;
32
33     /**
34      * the constructor, only to be used by {@link
35      * de.webman.util.scheduler.SchedulerMgr}
36      * @param _mgr the schedule mgr which controls this thread
37      **/

38     SchedulerThread(SchedulerMgr _mgr) {
39         mgr = _mgr;
40     }
41
42     /**
43      * stops the thread
44      **/

45     void stop() {
46         finished = true;
47     }
48
49     /**
50      * take off ...
51      **/

52     public void run() {
53         cat.debug("started");
54         try {
55             Thread.currentThread().sleep(mgr.getSleepTime()); // prewait
56
}
57         catch (InterruptedException JavaDoc ie) {
58             cat.debug("sleeptime interrupted by system");
59         }
60         
61         while (!finished) {
62             /* check one entry each time. */
63             mgr.checkNext();
64             
65             try {
66                 // sleep for some time
67
Thread.currentThread().sleep(mgr.getSleepTime());
68             }
69             catch (InterruptedException JavaDoc ie) {
70                 cat.debug("sleeptime interrupted by system");
71             }
72         }
73         cat.debug("stopped");
74     }
75 }
76
Popular Tags