|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.lth.cs.realtime.RTThread
This class defines a thread of execution in a real-time environment.
A normal java.lang.Thread
is not suitable to
real-time problems since it does not provide primitives like
sleepUntil()
, necessary to implement periodic real-time
processes properly, while, conversely, it provides means to asynchronously
change the priority of a thread which sometimes is not acceptable. Since some
methods of java.lang.Thread
are declared final
,
subclassing java.lang.Thread is not a solution.
Every real-time thread has a priority (if FixedPriority
is
implemented, it can be modified only before starting the thread); each thread
may or may not also be marked as a daemon. When code run by some thread
creates a new RTThread
object, the new thread has its priority
initially set equal to the priority of the creating thread, and it is set to
be a daemon thread if and only if the creating thread is a daemon.
Every RTThread
belongs to a RTThreadGroup
.
Every thread has a name for identification purposes. More than one thread may
have the same name. If a name is not specified when a thread is created, a
new name is generated for it.
The user may of course call Thread.currentThread
to obtain the
java.lang.Thread
which is encapsulated by the
RTThread
object, and, for instance, calling
interrupt
on that object will work as if the
interrupt
of RTThread
would have been called,
the user is supposed to retrieve the RTThread
object to gain
full support for embedded applications.
License
,
Thread
,
FixedPriority
,
RTThreadGroup
Field Summary | |
static int |
MAX_PRIORITY
The maximum priority that a thread can have. |
static int |
MIN_PRIORITY
The minimum priority that a thread can have. |
static int |
NORM_PRIORITY
The maximum priority that a thread can have. |
Constructor Summary | |
RTThread()
Allocates a new RTThread object with a newly generated
name in its father's RTThreadGroup . |
|
RTThread(RTThreadGroup group)
Allocates a new RTThread object with a newly generated
name in the specified RTThreadGroup . |
|
RTThread(RTThreadGroup group,
java.lang.String name)
Allocates a new RTThread object with the specified name in
the specified RTThreadGroup . |
|
RTThread(java.lang.String name)
Allocates a new RTThread object with the specified name in
its father's RTThreadGroup . |
Method Summary | |
void |
addListener(RTEventListener subscriber)
Subscribe on RTEvents from this source. |
static RTThread |
currentRTThread()
Returns a reference to the currently executing RTThread . |
static java.lang.Object |
currentThread()
Returns a reference to the currently executing thread object, which can be either an RTThread or a java.lang.Thread . |
static void |
dumpStack()
Prints a stack trace of the current thread. |
RTEventDispatcher |
getDispatcher()
Obtain the object that internally stores the subscriptions of events, often referred to as the listener list. |
Environment |
getEnv()
Environments not implemented yet. |
int |
getMaxTimeLag()
|
java.lang.String |
getName()
Returns this thread's name. |
int |
getPriority()
Obtain the priority of this thread. |
int |
getRTThreadId()
Obtain the unique RTThread number assigned to this thread
object. |
RTThreadGroup |
getThreadGroup()
Returns this thread's RTThreadGroup . |
Timebase |
getTimebase()
Time bases not implemented yet. |
void |
interrupt()
Interrupts this thread. |
static boolean |
interrupted()
Tests if the current thread has been interrupted. |
boolean |
isAlive()
Tests if this thread is alive. |
boolean |
isDaemon()
Tests if this thread is a daemon thread. |
boolean |
isInterrupted()
Tests if this thread has been interrupted without modifying the "interruption-flag". |
void |
join()
Waits for this thread to die. |
void |
join(long millis)
Waits at most millis milliseconds for this thread to die. |
void |
join(long millis,
int nanos)
Waits at most millis milliseconds plus nanos
nanoseconds for this thread to die. |
RTEvent |
putEvent(RTEvent ev)
Put the time-stamped event in the input buffer of this thread. |
void |
setDaemon(boolean on)
Marks this thread as either a daemon thread or a user thread. |
void |
setMaxTimeLag(int maxResponseTime)
|
void |
setName(java.lang.String name)
Changes the name of this thread to be equal to the argument name . |
void |
setPriority(int newPriority)
Changes the priority of this thread. |
static void |
sleep(long millis)
Sleep for (at least) millis ms, handled by RTSystem . |
static void |
sleep(long millis,
int nanos)
Sleep for (at least) millis ms plus nanos ns, handled by RTSystem . |
static void |
sleepUntil(long wakeUpTime)
Causes the currently executing thread to sleep (temporarily cease execution) until the specified moment in time. |
void |
start()
Causes this thread to begin execution. |
void |
terminate()
Interrupt and join. |
java.lang.String |
toString()
Returns a string representation of this thread, including the thread's name and priority. |
static void |
yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int MIN_PRIORITY
public static final int MAX_PRIORITY
public static final int NORM_PRIORITY
Constructor Detail |
public RTThread()
RTThread
object with a newly generated
name in its father's RTThreadGroup
. Automatically
generated names are of the form "RTThread-"+
n ,
where n is an integer.
public RTThread(java.lang.String name)
RTThread
object with the specified name in
its father's RTThreadGroup
.
name
- the name of the new thread.public RTThread(RTThreadGroup group)
RTThread
object with a newly generated
name in the specified RTThreadGroup
.
Automatically generated names are of the form "RTThread-"+
n , where n is an integer.
group
- the RTThreadGroup
of the new thread.public RTThread(RTThreadGroup group, java.lang.String name)
RTThread
object with the specified name in
the specified RTThreadGroup
.
name
- the name of the new thread.group
- the RTThreadGroup
of the new thread.Method Detail |
public void setMaxTimeLag(int maxResponseTime)
public int getMaxTimeLag()
public int getRTThreadId()
RTThread
number assigned to this thread
object. When a new thread object is created
public RTEvent putEvent(RTEvent ev)
putEvent
in interface RTEventListener
ev
- Event to process or buffer for processing
public RTEventDispatcher getDispatcher()
RTEvent
s gets a call
of putEvent
which typically only stores/buffers the event
for later processing by the receiving thread (object). Thus, the
EventSource
simply dispatches the event distribution,
hence the name dispatcher of the lister list storage object.
getDispatcher
in interface RTEventSource
RTEvent
listeners. The returned dispatcher corresponds to the
javax.swing.event.EventListenerList
, but enhanced
for real-time usage.public void addListener(RTEventListener subscriber)
RTEventSource
addListener
in interface RTEventSource
subscriber
- the object interested in getting the events
via its putEvent
method.public static RTThread currentRTThread()
RTThread
.
If the currently executing thread is not an RTThread
,
null
is returned.
public static java.lang.Object currentThread()
RTThread
or a java.lang.Thread
.
Since those two types of threads do not share a common thread base class,
the return type is Object
.
public static final void yield()
java.lang.Thread
,yield
of that class is
called.
public static void sleepUntil(long wakeUpTime) throws RTInterrupted, RTDelayed
wakeUpTime
- the time to wake up.
RTInterrupted
- if another thread has interrupted this thread.
RTDelayed
- if execution continues more than maxTimeLag
too late.public static void sleep(long millis) throws RTInterrupted, RTDelayed
RTSystem
.
RTInterrupted
RTDelayed
RTSystem.sleep(long)
public static void sleep(long millis, int nanos) throws RTInterrupted, RTDelayed
RTSystem
.
RTInterrupted
RTDelayed
RTSystem.sleep(long,int)
public void start()
The result is that two threads are running concurrently: the current
thread (which returns from the call to the start
method)
and the other thread (which executes its run
method).
start
in interface Activity
java.lang.IllegalThreadStateException
- if the thread was already started.RTThread#run()
public void interrupt()
interrupted
or
isInterrupted
.
interrupted()
,
isInterrupted()
public static boolean interrupted()
Note that interrupted
is a static method, while
isInterrupted
is called on this Thread
instance.
true
if the current thread has been interrupted;
false
otherwise.interrupt()
,
isInterrupted()
public boolean isInterrupted()
Note that isInterrupted
is called on this
RTThread
instance; by contrast, interrupted
is a static method.
true
if this thread has been interrupted;
false
otherwise.interrupt()
,
interrupted()
public final boolean isAlive()
isAlive
in interface Activity
true
if this thread is alive; false
otherwise.public final void setPriority(int newPriority) throws FixedPriorityError
FixedPriorityError
- If this thread is alive and implements the
FixedPriority
interface.
java.lang.IllegalArgumentException
- If the priority is not in the range
MIN_PRIORITY
to MAX_PRIORITY
.getPriority()
,
FixedPriority
public final int getPriority()
setPriority(int)
public final void setName(java.lang.String name)
name
.
name
- the new name for this thread.getName()
public final java.lang.String getName()
setName(java.lang.String)
public final RTThreadGroup getThreadGroup()
RTThreadGroup
.
RTThreadGroup
.public final void join(long millis) throws java.lang.InterruptedException
millis
milliseconds for this thread to die.
A timeout of 0
means to wait forever. A CyclicThread is
not allowed to join another thread. (TO FIX)
millis
- the time to wait in milliseconds.
java.lang.InterruptedException
- if another thread has interrupted the current thread.
java.lang.IllegalStateException
- if the calling thread is an instance of CyclicRTThread
.CyclicThread
public final void join(long millis, int nanos) throws java.lang.InterruptedException
millis
milliseconds plus nanos
nanoseconds for this thread to die.
millis
- the time to wait in milliseconds.nanos
- 0-999999 additional nanoseconds to wait.
java.lang.IllegalArgumentException
- if the value of millis is negative the value of nanos is
not in the range 0-999999.
java.lang.InterruptedException
- if another thread has interrupted the current thread.public final void join() throws java.lang.InterruptedException
join
in interface Activity
java.lang.InterruptedException
- if another thread has interrupted the current thread.public void terminate()
terminate
in interface Activity
public static void dumpStack()
Throwable.printStackTrace()
public final void setDaemon(boolean on)
This method must be called before the thread is started.
on
- if true
, marks this thread as a daemon thread.
java.lang.IllegalThreadStateException
- if this thread is active.isDaemon()
public final boolean isDaemon()
true
if this thread is a daemon thread;
false
otherwise.setDaemon(boolean)
public Timebase getTimebase()
getTimebase
in interface Activity
public Environment getEnv()
getEnv
in interface Activity
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |