public class Timed extends AsynchronouslyInterruptedException
Timed is a subclass of AsynchronouslyInterruptedException that permit the execution of code provided in an instance of Interruptible with a given time out. After the time out is reached, the code will be interrupted by throwing this instance of AsynchronouslyInterruptedException.
No memory allocation will be performed after the creation of this Timed instance, several invocation of doInterruptible may hence be performed without additional memory allocation.
StaticThrowable.Hidden
Constructor and Description |
---|
Timed(HighResolutionTime<?> time)
Constructor to create a new instance of Timed with the given time
out.
|
Modifier and Type | Method and Description |
---|---|
boolean |
doInterruptible(Interruptible logic)
doInterruptible executes the run() method of the provided
Interruptible logic with the time-out provided to the constructor
of this Timed or set via resetTime.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
void |
resetTime(HighResolutionTime<?> time)
resetTime sets the time out for the next invocation of
doInterruptible to a new value.
|
clear, disable, enable, fillInStackTrace, fire, get, getCause, getGeneric, getSingleton, getStackTrace, initCause, isEnabled, printStackTrace, printStackTrace, printStackTrace, setStackTrace, throwPending
addSuppressed, getLocalizedMessage, getMessage, getSuppressed, toString
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getLocalizedMessage, getMessage, init, init, init, init, isStatic, writeReplace
public Timed(HighResolutionTime<?> time) throws StaticIllegalArgumentException
Constructor to create a new instance of Timed with the given time out.
StaticIllegalArgumentException
- if time is null.time
- the timeout when the execution the Interruptible
logic should be stopped.public boolean doInterruptible(Interruptible logic)
doInterruptible
in class AsynchronouslyInterruptedException
StaticIllegalArgumentException
- iff the provided logic parameter
is null.logic
- Contains the run() method that specifies the logic
to be executed in an interruptible way.public void resetTime(HighResolutionTime<?> time)
time
- the new time out. It may be null to keep the time out
unchanged.protected void finalize()
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
WeakReference
,
PhantomReference
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2025 aicas GmbH. All Rights Reserved.