|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--se.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
whould have been
called, the ser is supposed to retrieve the RTThread
object to gain full support for embedded applications.
Thread
,
FixedPriority
,
RTThreadGroup
Field Summary | |
protected int |
defaultEventBufferSize
Default size of the event buffer, used by constructor possibly after being changed by some subclass constructor. |
protected RTEventListenerList |
listenerList
The list of the listeners of this thread. |
protected RTEventBuffer |
mailbox
The event inbut buffer. |
static int |
MAX_PRIORITY
The maximum priority that a thread can have. |
static int |
MIN_PRIORITY
The minimum 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. |
|
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 | |
static RTThread |
currentRTThread()
Returns a reference to the currently executing RTThread object. |
static void |
dumpStack()
Prints a stack trace of the current thread. |
java.lang.String |
getName()
Returns this thread's name. |
int |
getPriority()
Returns this thread's priority. |
RTThreadGroup |
getRTThreadGroup()
Returns this thread's RTThreadGroup . |
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. |
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. |
void |
putEvent(RTEvent ev)
Put the time-stamped event in the input buffer of this thread. |
protected abstract void |
run()
Corresponds to java.lang.Thread.run and has the same semantics. |
void |
setDaemon(boolean on)
Marks this thread as either a daemon thread or a user thread. |
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)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. |
static void |
sleep(long millis,
int nanos)
Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds. |
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. |
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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected RTEventBuffer mailbox
protected int defaultEventBufferSize
protected RTEventListenerList listenerList
RTEventListenerList
public static final int MIN_PRIORITY
public static final int MAX_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 putEvent(RTEvent ev)
putEvent
in interface RTEventListener
se.lth.cs.realtime.event.RTEventListener
e
- Event to handlepublic static RTThread currentRTThread()
RTThread
,
null is retured.public static void yield()
public static void sleepUntil(long wakeUpTime) throws java.lang.InterruptedException
wakeUpTime
- the time to wake up.java.lang.InterruptedException
- if another thread has interrupted
this thread.public static void sleep(long millis) throws java.lang.InterruptedException
millis
- the length of time to sleep in milliseconds.java.lang.IllegalArgumentException
- if the value of millis is
negative.java.lang.InterruptedException
- if another thread has interrupted
this thread.Object.notify()
public static void sleep(long millis, int nanos) throws java.lang.InterruptedException
millis
- the length of time to sleep in milliseconds.nanos
- 0-999999 additional nanoseconds to sleep.java.lang.IllegalArgumentException
- if the value of millis is
negative or the value of nanos is not in the range
0-999999.java.lang.InterruptedException
- if another thread has interrupted
this thread.Object.notify()
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).
IllegalThreadStateException
- if the thread was already
started.run()
protected abstract void run()
Thread.run()
,
start()
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()
true
if this thread is alive;
false
otherwise.public final void setPriority(int newPriority) throws FixedPriorityException
If this thread implements the FixedPriority interface and is alive, an exception is thrown.
FixedPriorityException
- If this thread is declared to implement
the FixedPriority
interface and is alive.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 getRTThreadGroup()
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 CyclicRTThread 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
java.lang.InterruptedException
- if another thread has interrupted the
current thread.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.IllegalThreadStateException
- if this thread is active.isDaemon()
public final boolean isDaemon()
true
if this thread is a daemon thread;
false
otherwise.setDaemon(boolean)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |