|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--se.lth.cs.realtime.RTThread | +--se.lth.cs.realtime.CyclicThread | +--se.lth.cs.realtime.PeriodicThread
This class models a real-time thread with periodic behaviour.
Such a thread loops performing an action once every period
milliseconds (if FixedPeriod
is implemented,
the period can be modified only before the thread is started).
Being a CyclicThread
,
a PeriodicThread
may be suspended and resumed
by other threads. By default, the calls to perform
which would have been executed during the suspension time are
issued after the resumption.
Field Summary | |
protected long |
baseTime
The absolute time (calculated in ms since midnight, January 1, 1970 UTC) used to compute the time of the next call to perform . |
Fields inherited from class se.lth.cs.realtime.RTThread |
defaultEventBufferSize, listenerList, mailbox, MAX_PRIORITY, MIN_PRIORITY |
Constructor Summary | |
PeriodicThread(long period)
Allocates a new PeriodicThread object. |
|
PeriodicThread(RTThreadGroup group,
long period)
Allocates a new PeriodicThread object. |
|
PeriodicThread(RTThreadGroup group,
java.lang.String name,
boolean privateQueue,
long period)
Allocates a new PeriodicThread object. |
|
PeriodicThread(RTThreadGroup group,
java.lang.String name,
long period)
Allocates a new PeriodicThread object. |
|
PeriodicThread(java.lang.String name,
long period)
Allocates a new PeriodicThread object. |
Method Summary | |
long |
getPeriod()
Returns the period of this thread, in milliseconds. |
protected void |
perform()
Does nothing. |
void |
setPeriod(long period)
Sets the period, in milliseconds, of this thread. |
void |
start()
Overrides RTThread.start . |
java.lang.String |
toString()
Returns a string representation of this thread, including the thread's name, priority and period in milliseconds. |
protected void |
waitToPerform()
Wait until the beginning of the next period. |
Methods inherited from class se.lth.cs.realtime.CyclicThread |
isSuspended, onResuming, resume, run, stop, suspend |
Methods inherited from class se.lth.cs.realtime.RTThread |
currentRTThread, dumpStack, getName, getPriority, getRTThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, putEvent, setDaemon, setName, setPriority, sleep, sleep, sleepUntil, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected long baseTime
perform
.
PLEASE NOTE: in this implementation, this field is given
protected visibility, thus allowing easy modifications from subclasses,
but also, possibly, from within other threads of execution, which could
result in inconsistent values of baseTime
, being a long
.
Hence, care must be taken that baseTime
be accessed only
by this thread itself (i.e. in onResuming
).
Constructor Detail |
public PeriodicThread(long period)
PeriodicThread
object.
Equivalent to PeriodicThread(null, null, true, period)
.
period
- the period of the new thread, in milliseconds.java.lang.IllegalArgumentException
- if the period is not positive.PeriodicThread(RTThreadGroup,
java.lang.String, boolean, long)
public PeriodicThread(java.lang.String name, long period)
PeriodicThread
object.
Equivalent to PeriodicThread(null, name, true, period)
.
name
- the name of the new thread.period
- the period of the new thread, in milliseconds.java.lang.IllegalArgumentException
- if the period is not positive.PeriodicThread(RTThreadGroup,
java.lang.String, boolean, long)
public PeriodicThread(RTThreadGroup group, long period)
PeriodicThread
object.
Equivalent to PeriodicThread(group, null, true, period)
.
group
- this thread's RTThreadGroup
.period
- the period of the new thread, in milliseconds.java.lang.IllegalArgumentException
- if the period is not positive.PeriodicThread(RTThreadGroup,
java.lang.String, boolean, long)
public PeriodicThread(RTThreadGroup group, java.lang.String name, long period)
PeriodicThread
object.
Equivalent to PeriodicThread(group, name, true, period)
.
name
- the name of the new thread.group
- this thread's RTThreadGroup
.period
- the period of the new thread, in milliseconds.java.lang.IllegalArgumentException
- if the period is not positive.PeriodicThread(RTThreadGroup,
java.lang.String, boolean, long)
public PeriodicThread(RTThreadGroup group, java.lang.String name, boolean privateQueue, long period)
PeriodicThread
object.
It is possible to specify whether this thread should use a private object to wait on, when suspended.
name
- the name of the new thread.group
- this thread's RTThreadGroup
.privateQueue
- whether this thread should use a private queue.period
- the period of the new thread, in milliseconds.java.lang.IllegalArgumentException
- if the period is not positive.CyclicThread.CyclicThread(RTThreadGroup, java.lang.String, boolean)
Method Detail |
public void start()
RTThread.start
. Perform the settings
needed to ensure a correct periodical behaviour and calls
RTThread.start
, which in turns causes the call
of CyclicThread.run
.start
in class RTThread
RTThread.start()
,
CyclicThread.run()
protected void perform()
PeriodicEvent
generator only.perform
in class CyclicThread
PeriodicEvent
protected void waitToPerform() throws java.lang.InterruptedException
waitToPerform
in class CyclicThread
java.lang.InterruptedException
- if another thread has interrupted this one.public long getPeriod()
public void setPeriod(long period) throws FixedPeriodException
FixedPeriod
and is alive, an
exception is thrown.period
- the new period of this thread, in ms.java.lang.IllegalArgumentException
- if the period is not positive.FixedPeriodException
- if this thread implements
FixedPriority
and is alive.public java.lang.String toString()
toString
in class CyclicThread
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |