public class RealtimeThreadGroup
extends java.lang.ThreadGroup
ThreadGroup
in which a RealtimeThread
instance may be started, as well as a convention Thread
.
Limits for what realtime scheduler and scheduling parameters can be
enforced on all tasks in this group. A normal ThreadGroup
may not contain an instance of Schedulable
or instances of
RealtimeThreadGroup
. Every thread is in some instance of
ThreadGroup
and every instance of RealtimeThread
is
in some instance of RealtimeThreadGroup
. This means that the
main
thread of a realtime Java implementation must be in an
instance of this class, not a normal ThreadGroup
.Caution: This class is explicitly unsafe for multithreading when being changed. Code that mutates instances of this class should synchronize at a higher level.
Constructor and Description |
---|
RealtimeThreadGroup(RealtimeThreadGroup parent,
java.lang.String name)
Creates a new realtime thread group with its scheduler type inherited from
parent . |
RealtimeThreadGroup(RealtimeThreadGroup parent,
java.lang.String name,
java.lang.Class<? extends Scheduler> scheduler)
Creates a new realtime thread group with its scheduler type inherited from
parent . |
RealtimeThreadGroup(java.lang.String name)
Creates a new group with the current
ThreadGroup instance
as its parent and that parent's scheduler type for its scheduler type. |
Modifier and Type | Method and Description |
---|---|
SchedulingParameters |
getMaxEligibility()
Finds the upper bound on scheduling eligibility that tasks in this
group may have.
|
java.lang.Class<? extends Scheduler> |
getScheduler()
Finds the type of scheduler tasks in this group may use.
|
RealtimeThreadGroup |
setMaxEligibility(SchedulingParameters parameters)
Sets the upper bound on scheduling eligibility that tasks in this
group may have.
|
void |
visitThreadGroups(java.util.function.Consumer<java.lang.ThreadGroup> visitor)
Performs some operation on all the groups in the current group.
|
void |
visitThreadGroups(java.util.function.Consumer<java.lang.ThreadGroup> visitor,
boolean recursive)
Performs some operation on all th groups in the current group.
|
void |
visitThreads(java.util.function.Consumer<java.lang.Thread> visitor)
Visit all
java.lang.Thread instances contained by this
group. |
void |
visitThreads(java.util.function.Consumer<java.lang.Thread> visitor,
boolean recurse)
Visit all
java.lang.Thread instances contained by this
group and optionally all ThreadGroup instances contained within
recursively. |
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
public RealtimeThreadGroup(RealtimeThreadGroup parent, java.lang.String name, java.lang.Class<? extends Scheduler> scheduler)
parent
.parent
- The parent group of the new groupname
- The name of the new groupscheduler
- a scheduler class limiting the schedulers allowed for
scheduling group members. When null
inherits from parent.
Instances of java.lang.ThreadGroup
do not have a scheduler
and may not contain instances of RealtimeSchedulerGroup
.StaticIllegalStateException
- when the parent ThreadGroup
instance is not an instance of RealtimeThreadGroup
.IllegalAssignmentError
- when the parent
ThreadGroup
instance is not assignable to this.public RealtimeThreadGroup(RealtimeThreadGroup parent, java.lang.String name)
parent
.parent
- The parent group of the new groupname
- The name of the new groupStaticIllegalStateException
- when the parent ThreadGroup
instance is not an instance of RealtimeThreadGroup
.IllegalAssignmentError
- when the parent
ThreadGroup
instance is not assignable to this.public RealtimeThreadGroup(java.lang.String name) throws StaticIllegalStateException, IllegalAssignmentError
ThreadGroup
instance
as its parent and that parent's scheduler type for its scheduler type.
That parent must be an instance of RealtimeThreadGroup
.
The primordial realtime thread group has Scheduler.class
as its
scheduler type.name
- The name of the new groupStaticIllegalStateException
- when the parent ThreadGroup
instance is not an instance of RealtimeThreadGroup
.IllegalAssignmentError
- when the parent
ThreadGroup
instance is not assignable to this.public java.lang.Class<? extends Scheduler> getScheduler()
class<Scheduler>
, but it may be set to any subtype.public SchedulingParameters getMaxEligibility()
PriorityParameters
, it gives the maximum base priority any
task in this group.SchedulingParamters
, not one of its
subclasses, with an affinity that contains all processors
available to the process. This may not be null
.public RealtimeThreadGroup setMaxEligibility(SchedulingParameters parameters) throws StaticIllegalStateException
PriorityParameters
, it sets the maximum base priority any
task in this group may have. When a task in the group has a higher
eligibility than specified in parameters
, the task's
eligibility is silently set to the max specified in parameters
.
When the new eligibility is higher than that of any parent's eligibility,
then eligibility is set to the minimum of those priorities.
When a child of this
RealtimeThreadGroup
has a higher max eligibility than specified in
parameters
, its max eligibility is silently set to the max
specified in parameters
as if setMaxEligibility
were
invoked on it recursively.
When a task in this RealtimeThreadGroup
or a child of this
RealtimeThreadGroup
has previously had its maximum eligibility
reduced by a call to this method, setting a higher maximum
eligibility via this method will not automatically reraise its
eligibility.
Please note that this method is not thread safe, as it uses methods
from ThreadGroup that are not thread safe.
parameters
- The SchedulingParameter instance denoting the new
upper bound on the scheduling eligibility of threads in this group.this
StaticIllegalArgumentException
- when parameters
are not
consistent with the scheduler type. The scheduler specified
must be specific enough that only mutually compatible
SchedulingParameters
could be set. For example,
Scheduler
is not sufficient to restrict the scheduling
parameters to compatible types, but PriorityScheduler
does
since all PriorityScheduler
instances require
PriorityParameters
.StaticIllegalStateException
- when parameters
is a
higher eligibility than the max eligibility enforced by a
SchedulingParameters
above this
in the
hierarchy.public void visitThreads(java.util.function.Consumer<java.lang.Thread> visitor, boolean recurse) throws ForEachTerminationException
java.lang.Thread
instances contained by this
group and optionally all ThreadGroup
instances contained within
recursively.visitor
- A consumer of each schedulable instance.recurse
- A boolean to indicated that the visit should be recursive.ForEachTerminationException
public void visitThreads(java.util.function.Consumer<java.lang.Thread> visitor) throws ForEachTerminationException
java.lang.Thread
instances contained by this
group. It is equivalent to calling visitThreads(Consumer, boolean)
with recurse
set to false
.visitor
- A consumer of each thread instanceForEachTerminationException
- when the visitor is prematurely ended.public void visitThreadGroups(java.util.function.Consumer<java.lang.ThreadGroup> visitor) throws ForEachTerminationException
visitor
does not
throw a ForEachTerminationException
. Thus the traversal can be
prematurely ended by visitor
throwing this exception, e.g., when
a particular element is found. It is equivalent to a call to
visitThreadGroups(Consumer, boolean)
with recurse
set to false
.visitor
- The function to be called on each child thread group.ForEachTerminationException
- when the traversal ends prematurely.public void visitThreadGroups(java.util.function.Consumer<java.lang.ThreadGroup> visitor, boolean recursive)
visitor
does not
throw a ForEachTerminationException
. Thus the traversal can be
prematurely ended by visitor
throwing this exception, e.g., when
a particular element is found.visitor
- The function to be called on each child thread group.recursive
- A boolean to determine whether or not all subgroups
are included, where true
means yes and false
means no.ForEachTerminationException
- when the traversal ends prematurely.