01: package com.rimfaxe.thread;
02:
03: /** The abstract class, MutableThread implements the MutableRunnable interface.
04: * It is abstract, since it does not implement the run method, which must
05: * be implemented by all instances inheriting from this class.
06: */
07: public abstract class MutableThread implements MutableRunnable {
08:
09: private int mPriority = Thread.NORM_PRIORITY;
10: Thread mThisThread = null;
11: String mThreadName = "MutableThread";
12:
13: /** The constructor for MutableThread has no passed parameter. It invokes
14: * a call to the createThread method, which in turn creates the owned thread.
15: */
16: public MutableThread() {
17: createThread();
18: }
19:
20: /** The implemented start method starts the thread.
21: */
22: public void start() {
23: mThisThread.start();
24:
25: }
26:
27: /** This is the implemented start method which first sets the passed parameter
28: * for priority and then invokes the start method for the thread.
29: */
30: public void start(int aPriority) // this method starts the thread with a given priority.
31: {
32: setPriority(aPriority);
33: start();
34:
35: }
36:
37: /** This method is provided for test purposes only
38: * the method is deprecated.
39: */
40: public void stop() {
41: mThisThread.stop(); // deprectated method accessed for test purposes only
42: }
43:
44: /** This method provides the test for isAlive required for monitoring thread status
45: *
46: */
47: public boolean isAlive() {
48: return mThisThread.isAlive();
49: }
50:
51: /** The setName method passes the string for assignment to the thread
52: * as name. This string is retained as an attribute for assignment
53: * to any thread which is owned by this mutable object.
54: */
55: public void setName(String aThreadName) {
56: mThreadName = aThreadName;
57: if (mThisThread != null)
58: mThisThread.setName(aThreadName);
59:
60: }
61:
62: /** The getName method returns the assigned name for the thread.
63: */
64: public String getName() {
65: return mThreadName;
66: }
67:
68: /** The setPriority(int) method passes the parameter for priority to the
69: * mutable object This priority is assigned to any thread owned by this
70: * object.
71: */
72: public void setPriority(int aPriority) {
73: mPriority = aPriority;
74: if (mThisThread != null)
75: mThisThread.setPriority(mPriority);
76: }
77:
78: /** The createThread method makes a new thread, the old thread is no longer
79: * used by this mutable object.
80: */
81: public void createThread() {
82: mThisThread = new Thread(this , mThreadName);
83: mThisThread.setPriority(mPriority);
84: }
85:
86: // this is abstract to enforce implementation
87: /** This abstract method for run must be implemented by all extending classes.
88: */
89: public abstract void run();
90:
91: }
|