01: package de.webman.util.scheduler;
02:
03: import org.apache.log4j.Category;
04:
05: /**
06: * The scheduler master thread which checks for scheduler service to kick
07: * off. Should be a private or package class inside SchedulerMgr, but this
08: * is not allowed by JTest. So its here.
09: *
10: * @author <a href="mailto:gregor.klinke@webman.de">Gregor Klinke</a>
11: * @version $Revision: 1.2 $
12: **/
13: public class SchedulerThread implements Runnable {
14: /* $Id: SchedulerThread.java,v 1.2 2002/04/12 12:45:53 gregor Exp $ */
15: /**
16: * the logging facility
17: **/
18: private static Category cat = Category
19: .getInstance(SchedulerThread.class);
20:
21: /**
22: * the parent ScheduleMgr
23: **/
24: private SchedulerMgr mgr;
25:
26: /**
27: * is this thread finished
28: **/
29: private boolean finished = false;
30:
31: /**
32: * the constructor, only to be used by {@link
33: * de.webman.util.scheduler.SchedulerMgr}
34: * @param _mgr the schedule mgr which controls this thread
35: **/
36: SchedulerThread(SchedulerMgr _mgr) {
37: mgr = _mgr;
38: }
39:
40: /**
41: * stops the thread
42: **/
43: void stop() {
44: finished = true;
45: }
46:
47: /**
48: * take off ...
49: **/
50: public void run() {
51: cat.debug("started");
52: try {
53: Thread.currentThread().sleep(mgr.getSleepTime()); // prewait
54: } catch (InterruptedException ie) {
55: cat.debug("sleeptime interrupted by system");
56: }
57:
58: while (!finished) {
59: /* check one entry each time. */
60: mgr.checkNext();
61:
62: try {
63: // sleep for some time
64: Thread.currentThread().sleep(mgr.getSleepTime());
65: } catch (InterruptedException ie) {
66: cat.debug("sleeptime interrupted by system");
67: }
68: }
69: cat.debug("stopped");
70: }
71: }
|