public class RealtimeThreadGroup extends 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
.
Please note that some of the method of this class are not thread
safe, as they use methods from ThreadGroup that are not thread safe.Constructor and Description |
---|
RealtimeThreadGroup(RealtimeThreadGroup parent,
String name)
Creates a new realtime thread group with its scheduler type inherited from
parent . |
RealtimeThreadGroup(RealtimeThreadGroup parent,
String name,
Class<? extends Scheduler> scheduler)
Creates a new realtime thread group with its scheduler type
inherited from
parent . |
RealtimeThreadGroup(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 |
---|---|
int |
activeCount()
Returns an estimate of the number of active threads in this thread
group and its subgroups.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
SchedulingParameters |
getMaxEligibility()
Finds the upper bound on scheduling eligibility that tasks in this
group may have.
|
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(Consumer<ThreadGroup> visitor)
Performs some operation on all the groups in the current group.
|
void |
visitThreadGroups(Consumer<ThreadGroup> visitor,
boolean recurse)
Performs some operation on all the groups in the current group.
|
void |
visitThreads(Consumer<Thread> visitor)
Visit all
java.lang.Thread instances contained by this
group. |
void |
visitThreads(Consumer<Thread> visitor,
boolean recurse)
Visit all
java.lang.Thread instances contained by this
group and optionally all ThreadGroup instances contained within
recursively. |
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, String name, Class<? extends Scheduler> scheduler)
parent
.StaticIllegalStateException
- when the scheduler of parent
does not subsume scheduler
.IllegalAssignmentError
- when the parent ThreadGroup
instance is not assignable to this.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
.public RealtimeThreadGroup(RealtimeThreadGroup parent, String name) throws StaticIllegalStateException, IllegalAssignmentError
parent
.StaticIllegalStateException
- when the parent ThreadGroup
instance is not an instance of RealtimeThreadGroup
.IllegalAssignmentError
- when the parent
ThreadGroup
instance is not assignable to this.parent
- The parent group of the new groupname
- The name of the new grouppublic RealtimeThreadGroup(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.StaticIllegalStateException
- when the parent ThreadGroup
instance is not an instance of RealtimeThreadGroup
.IllegalAssignmentError
- when the parent
ThreadGroup
instance is not assignable to this.name
- The name of the new grouppublic int activeCount()
ThreadGroup
The value returned is only an estimate because the number of threads may change dynamically while this method traverses internal data structures, and might be affected by the presence of certain system threads. This method is intended primarily for debugging and monitoring purposes.
activeCount
in class ThreadGroup
public 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.null
when no such bound has been specified.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.
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.parameters
- The SchedulingParameter instance denoting the new
upper bound on the scheduling eligibility of threads in this group.this
public void visitThreads(Consumer<Thread> visitor, boolean recurse) throws ForEachTerminationException
java.lang.Thread
instances contained by this
group and optionally all ThreadGroup
instances contained within
recursively.ForEachTerminationException
- when the visitor is prematurely ended.visitor
- A consumer of each schedulable instance.recurse
- A boolean to indicated that the visit should be recursive.public void visitThreads(Consumer<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
.ForEachTerminationException
- when the visitor is prematurely ended.visitor
- A consumer of each thread instancepublic void visitThreadGroups(Consumer<ThreadGroup> visitor, boolean recurse) 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.ForEachTerminationException
- when the traversal ends prematurely.visitor
- The function to be called on each child thread group.recurse
- A boolean to determine whether or not all subgroups
are included, where true
means yes and false
means no.public void visitThreadGroups(Consumer<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
.ForEachTerminationException
- when the traversal ends prematurely.visitor
- The function to be called on each child thread group.protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
JamaicaVM: Realtime code requires special care when using finalize:
NOTE: The use of finalize() is strongly discouraged for realtime or safety-critical code. This method should only be used for debugging purposes. If used as a last resort to reclaim non-memory resources, finalize() should indicate the resource leak with a loud error message.
There is no guarantee that finalize() will be called, the memory management may decide not to reclaim this object's memory or to delay the call to finalize() to an unspecified point in time. It is therefore recommended never to use the finalize method to release any resources (files, network connections, non-Java memory, etc.) since releasing of these resource may be delayed perpetually.
The order of finalization is not specified, i.e., the finalize method of any two objects that become unreachable may be called in an arbitrary order. It therefore has to be assumed that when finalize() is called on an object, that the finalize() method of any object that is only reachable through this object() has been called as well or is called simultaneously by another thread.
The presence of a finalize-method in any sub-class of Object causes the reclamation of the memory of this object to be delayed until the finalize() method has been executed. The finalize() method is typically executed by the finalizer thread (that may run at a low priority) or by a call to Runtime.runFinalization().
Any code sequence that creates instances of a class that defines a finalize() method must therefore ensure that sufficient CPU time is allocated to the finalizer thread or that Runtime.runFinalization() is called regularly such that the finalize() methods can be executed and the object's memory can be reclaimed.
The finalize method itself should never block or run for long times since it would otherwise block the finalizer thread or the thread that called Runtime.runFinalization() and prevent the execution other finalize() method and consequently prevent the reclamation of these object's memory.
For objects that are allocated in a javax.realtime.memory.ScopedMemory, the finalize() methods will be called when this scoped memory is exited by the last thread. Unlike HeapMemory, which is controlled by the garbage collector, ScopedMemory provides a defined execution point for the finalize() mehods and it is therefore safer to use finalize() here.
finalize
in class Object
Throwable
- the Exception
raised by this methodWeakReference
,
PhantomReference
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2021 aicas GmbH. All Rights Reserved.