public static final class IntegerIdPool.Id extends Object
Integer identifier. The numeric value (as returned by the
method) is guaranteed to be unique for the whole life-time of this
object, meaning that no other ID acquired from the same
IntegerIdPool will return the same numeric identifier. However,
once this ID has been released, it might be reused by a newly acquired
ID, depending on the ID pool's configuration.
This ID (and its associated numeric identifier) are automatically
released when this object is finalized. However, due to the inherently
unpredictable nature of garbage collection, it is strongly recommended to
explicitly release the ID once it is not needed any longer in order to
avoid exhaustion of the associated ID pool. The ID can be released
explicitly by calling its
Object.equals(Object) method of this class actually compares for
object equality, not equality of the numeric identifier. This is
reasonable because two different ID objects with the same numeric
identifier can only exist when at least one of these IDs has been
released. A released ID, however, is never considered the same ID as a
different released or alive ID.
|Modifier and Type||Method and Description|
Finalizes this object, releasing the ID.
Returns the numeric identifier for this ID.
Returns whether this ID is still alive or has already been released.
Releases this ID, returning it to the pool it has been acquired from.
Returns a string representation of this ID.
public int get()
Returns the numeric identifier for this ID. The numeric identifier can be used if the ID has to be passed to a component where this ID object cannot be passed (e.g. over the network). However, the numeric identifier might be reused for other identifiers in the future, depending on the configuration of the ID pool this ID has been acquired from.
IllegalStateException- if this ID has been released.
public void release()
Releases this ID, returning it to the pool it has been acquired from. Calling this method multiple times is not an error, however, the ID will only be released the first time this method is called. Subsequent calls to this method have no effect.
public boolean isAlive()
trueif this ID is still alive,
falseif it has been released by calling
public String toString()
get()) or the string "<released>" if this ID has already been released.
protected void finalize() throws Throwable
Finalizes this object, releasing the ID. This method calls
release() followed by
ensures that an ID is released when it is not used any longer.
However, the point in time at which
finalize() is called
is non-deterministic. For this reason, the
method should be called explicitly whenever this is feasible.
From the documentation of
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object. A
subclass overrides the
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 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.
Copyright © 2014–2016 aquenos GmbH. All rights reserved.