|
What threads are
running on your AVIDdirector? One way is you can to the run the process status
commands from the Ish command line 'ps' and get a display
like:
/root >
ps
Prio ID Parent Object UID Type tty State Name 13 6 0 0x10e6e0 0 Java ? Sleeping BackGround This doesn't tell
you much about the Thread, and you need to be at the Ish command line to perform
that.
In the M2M
Application framework, we have introduced the concept of the ThreadStatus
interface and class. If a Thread either implements the interface
(se.imsys.system.ThreadStatus or extends com.avidwireless.avidirector.ThreadStatus, it allows you to see
information such as:
/root >
m2mapp -t
M2MApp App running, performing control functions. Enter m2mapp -h for help. Thread List: Running 13 Threads/Processes: 6 BackGround MIN Alive 15 M2MApp.appTimer NORM Alive M2MApp.appTimer isRunning=true Last checked 35 sec ago 0 items on queue newTasksMayBeScheduled=true 11/14/2007 10:10:59AM 16 M2MApp.m2mIoTimer NORM Alive M2MApp.m2mIoTimer isRunning=true Last checked 35 sec ago 0 items on queue newTasksMayBeScheduled=true 11/14/2007 10:10:59AM 17 M2MApp.AT_Radio_Timer NORM Alive M2MApp.AT_Radio_Timer isRunning=true Last checked 4250 ms ago Last ran 4364 ms ago 1 items on queue newTasksMayBeScheduled=true 11/14/2007 10:11:31AM 18 PPPEventThread NORM Alive 25 Communicator.XPort NORM Alive threadRunning=true rcvQueue=0 sendQueue=0 items. Last ran 2sec 11/14/2007 10:11:33AM 26 M2MApp.SerialPortRadio_Timer NORM Alive M2MApp.SerialPortRadio_Timer isRunning=true Last checked 295 sec ago 0 items on queue newTasksMayBeScheduled=true 11/14/2007 10:06:40AM 30 M2MApp NORM Alive 27 AerocommRadioReceiver NORM Alive 28 AerocommRadioSender NORM Alive 29 N7AerocommListener NORM Alive 13 M2MApp NORM Alive 14 WatchDogTimer MAX Alive isRunning=true HWReset=true Monitoring 2 classes. Last ran 35sec ago 11/14/2007 10:11:00AM The information
after the thread state ("Alive" above) can be customized and the thread can
report on the amount of I/O (like Communicator.XPort), errors, or how long its been
since it ran.
To do this there are
two methods you need to add to your object: getThreadStatus() and
getLastTimeThreadRan(). These interfaces are defined in
se.imsys.system.ThreadStatus.
/** * Each thread can return a String with information about how the thread is running, such as * the last time it ran or if it is running or completed running * * @return Sting with the Thread status * @see se.imsys.system.ThreadStatus */ public String getThreadStatus(); /**
* Returns a long containing the system time the thread last ran. This is mainly for Threads * that are waiting for the an event before they run or periodic threads * * @return long with the System.currentTimeMillis the thread last ran * @see se.imsys.system.ThreadStatus */ public long getLastTimeThreadRan(); Below are two sample
implementations. The getThreadStatus() should return a String of no more than 80
characters describing the important things you need to know about the thread.
For the getLastTimeThreadRan() method, you need to probably implement a long
field that is updated with System.currentTimeMillis() each time it is
executed.
/**
* Each thread can return a String with information about how the thread is running, such as * the last time it ran or if it is running or completed running * * @return Sting with the Thread status * @see se.imsys.system.ThreadStatus */ public String getThreadStatus() { StringBuffer sb = new StringBuffer(80); sb.append("runThread=").append(runThread); sb.append(" Polling every "+(serverM2mxmlPollTime/1000)+" sec "); if (lastTimeRan > 0) sb.append(" Last ran ").append((System.currentTimeMillis()-lastTimeRan)/1000).append(" sec "); return sb.toString(); } /**
* Returns a long containing the system time the thread last ran. This is mainly for Threads * that are waiting for the an event before they run or periodic threads * * @return long with the System.currentTimeMillis the thread last ran * @see se.imsys.system.ThreadStatus */ public long getLastTimeThreadRan() { return lastTimeRan; } Doing this will
allow this information to be returned with the person runs 'm2mapp -t' from the
Ish command line, or if M2MApp is running in the foreground, then can enter 't'
to get the list.
So how do you
identify your thread as implementing these methods?
1. Have your thread
extend com.avidwireless.avidirector.ThreadStatus
instead of java.lang.Thread, and have these methods implemented in your
thread.
2. Have your class
implement Runnable, and when you create the Thread instance to run, create the
thread as a ThreadStatus. For example, in your class:
implements Runnable thread = new ThreadStatus(this)
{
/** * Each thread can return a String with information about how the thread is running, such as * the last time it ran or if it is running or completed running * * @return Sting with the Thread status * @see se.imsys.system.ThreadStatus */ public String getThreadStatus() { StringBuffer sb = new StringBuffer(80); sb.append("threadRunning=").append(threadRunning); if (sensors != null) sb.append(" Controlling ").append(sensors.length).append(" sensors."); if (lastTimeRan > 0) sb.append(" Last ran ").append((System.currentTimeMillis()-lastTimeRan)).append("ms ago "); return sb.toString(); } /**
* Returns a long containing the system time the thread last ran. This is mainly for Threads * that are waiting for the an event before they run or periodic threads * * @return long with the System.currentTimeMillis the thread last ran * @see se.imsys.system.ThreadStatus */ public long getLastTimeThreadRan() { return lastTimeRan; } }; 3. Implement your
Thread as a TimerTask. The java.util.TimerTask
in AVIDM2MApp implements the Thread status and tracks when it is
run.
|
| |||||||||||
| Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy |
| ©2008 Google |