Pool must implement the Poolable interface
and adhere to its contract.
Pools call allocate on Allocators with the
specific Slot that they want a Poolable allocated for. The Slot
represents a location in the pool, that can fit an object and make it
available for others to claim.
The contract of the Poolable interface is, that when release() is
called on the Poolable, it must in turn call Slot#release(Poolable)
on the specific Slot object that it was allocated with, giving itself as the
Poolable parameter.
A simple correct implementation of the Poolable interface looks like this:
[source,java]
----
include::../src/test/java/examples/Examples.java[tag=poolableGenericExample]
----
This can be shortened further by extending the BasePoolable class:
[source,java]
----
include::../src/test/java/examples/Examples.java[tag=poolableBaseExample]
----
It is also possible to directly use the Pooled implementation, which
implements both `Poolable` and AutoCloseable, and holds a
reference to the actual object being pooled.
Memory effects: The release of an object happens-before it is claimed
by another thread, or deallocated.
BasePoolable, Pooled
| Modifier and Type | Method and Description |
|---|---|
| public void | release()
Release this Poolable object back into the pool from where it came, so that others can claim it, or the pool deallocate it if it has expired. |
| release | back to summary |
|---|---|
| public void release() Release this Poolable object back into the pool from where it came,
so that others can claim it, or the pool deallocate it if it has
expired.
A call to this method MUST delegate to a call to
| |