public class ImmortalConstraint extends ResourceConstraint<ImmortalConstraint>
Constructor and Description |
---|
ImmortalConstraint(RealtimeThreadGroup group,
long limit)
Create a new contraint for the given RealtimeThreadGroup.
|
Modifier and Type | Method and Description |
---|---|
long |
available()
Determine how much of the resource are available for use.
|
static ImmortalConstraint |
currentConstraint()
Determine the processing constraint for the current execution context.
|
static ImmortalConstraint |
currentConstraint(Thread thread)
Determine the processing constraint for the give execution context.
|
static ImmortalConstraint |
currentConstraint(ThreadGroup group)
Determine the processing constraint for the give execution context.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
long |
getBudget()
Determine the total amount of a memory under the control of this
resource constraint instance.
|
static ImmortalConstraint |
getRootConstraint()
Get the root instance for this constraint type.
|
boolean |
isEnforcing()
Determine whether or not enforcing is in effect.
|
void |
start()
Start applying this constraint to is tasks.
|
void |
stop()
Stop applying this constraint to is tasks.
|
long |
used()
Determine how much of the resource have been used of the amount available.
|
getNotificationHandler, getParent, getRealtimeThreadGroup, governs, governs, governs, setNotificationHandler, visitBorrowers, visitGoverned
public ImmortalConstraint(RealtimeThreadGroup group, long limit)
group
- The RealtimeThreadGroup
to govern.limit
- the amount of memory to take from its parent to manage.public static ImmortalConstraint getRootConstraint()
public static ImmortalConstraint currentConstraint()
public static ImmortalConstraint currentConstraint(Thread thread)
thread
- The given execution context.public static ImmortalConstraint currentConstraint(ThreadGroup group)
thread
- The given execution context.public boolean isEnforcing()
isEnforcing
in class ResourceConstraint<ImmortalConstraint>
true
when yes and false
when not.public void start()
start
in class ResourceConstraint<ImmortalConstraint>
public void stop()
stop
in class ResourceConstraint<ImmortalConstraint>
public long getBudget()
public long used()
public long available()
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 ResourceConstraint<ImmortalConstraint>
Throwable
- the Exception
raised by this methodWeakReference
,
PhantomReference
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2024 aicas GmbH. All Rights Reserved.