Poolable contained in the pool, as determined
by the configured allocator.
claim(Timeout) methods can be
called concurrently from multiple threads.
This is a strictly stronger guarantee than PoolTap provides.
Pools extend the PoolTap class, which provides the API for accessing
the objects contained in the pool.
Pools contain Poolable objects. When you claim an object in a pool,
you also take upon yourself the responsibility of eventually
releasing that object again. By far the most
common idiom to achieve this is with a `try-finally` clause:
[source,java]
----
include::../src/test/java/examples/Examples.java[tag=poolClaimExample]
----
The pools are resizable, and can have their capacity changed at any time
after they have been created.
All pools are configured with a certain size, the number of objects that the
pool will have allocated at any one time, and they can change this number on
the fly using the setTargetSize(int) method. The change does not
take effect immediately, but instead moves the "goal post" and leaves the
pool to move towards it at its own pace.
No guarantees can be made about when the pool will actually reach the target
size, because it might depend on how long it takes for a certain number of
objects to be released back into the pool.
[NOTE]
--
Pools created with Pool#of(Object[]) are _not_ resizable, and calling
Pool#setTargetSize(int) or ManagedPool#setTargetSize(int) will
cause an UnsupportedOperationException to be thrown.
--
Pools are themselves life-cycled, and should be shut down
when they are no longer needed.
Note that Pools are not guaranteed to have overwritten the
`Object#finalize()` method. Pools are expected to rely on explicit
clean-up for releasing their resources.
stormpot.PoolTap
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public static < The type of T extends Poolable> PoolBuilderPoolable that is created by the allocator,
and the type of objects that the configured pools will contain. | from(Allocator<T>
The allocator we want our pools to use. This cannot be
`null`. allocator)Get a |
| public static < The type of T extends Poolable> PoolBuilderPoolable that is created by the allocator,
and the type of objects that the configured pools will contain. | fromInline(Allocator<T>
The allcoator we want our pools to use. This cannot be `null`. allocator)Get a |
| public static < The type of T extends Poolable> PoolBuilderPoolable that is created by the allocator,
and the type of objects that the configured pools will contain. | fromThreaded(Allocator<T>
The allocator we want our pools to use. This cannot be
`null`. allocator)Get a |
| public abstract ManagedPool | Returns: TheManagedPool instance for this pool.Get the |
| public abstract int | Returns: The current target size of this pool.Get the currently configured target size of the pool. |
| public abstract PoolTap | Returns: A thread-localPoolTap.Get a |
| public final PoolTap | Returns: A thread-safePoolTap.Get a thread-safe |
| public static < The type of objects being pooled. T> Pool | |
| public abstract void | |
| public abstract Completion | Returns: ACompletion instance that represents the shut down
process.Initiate the shut down process on this pool, and return a
|
| Pool | back to summary |
|---|---|
| pack-priv Pool() | |
| from | back to summary |
|---|---|
| public static <T extends Poolable> PoolBuilder Get a
| |
| fromInline | back to summary |
|---|---|
| public static <T extends Poolable> PoolBuilder Get a
| |
| fromThreaded | back to summary |
|---|---|
| public static <T extends Poolable> PoolBuilder Get a
| |
| getManagedPool | back to summary |
|---|---|
| public abstract ManagedPool getManagedPool() Get the
| |
| getTargetSize | back to summary |
|---|---|
| public abstract int getTargetSize() Get the currently configured target size of the pool. Note that this is _not_ the number of objects currently allocated by the pool - only the number of allocations the pool strives to keep alive.
| |
| getThreadLocalTap | back to summary |
|---|---|
| public abstract PoolTap Get a | |
| getThreadSafeTap | back to summary |
|---|---|
| public final PoolTap Get a thread-safe | |
| of | back to summary |
|---|---|
| public static <T> Pool Build a | |
| setTargetSize | back to summary |
|---|---|
| public abstract void setTargetSize(int size) Set the target size for this pool. The pool will strive to keep this many
objects allocated at any one time.
If the new target size is greater than the old one, the pool will allocate
more objects until it reaches the target size. If, on the other hand, the
new target size is less than the old one, the pool will deallocate more
and allocate less, until the new target size is reached.
No guarantees are made about when the pool actually reaches the target
size. In fact, it may never happen as the target size can be changed as
often as one sees fit.
Pools that do not support a size less than 0 (which would deviate from the
standard configuration space) will throw an
| |
| shutdown | back to summary |
|---|---|
| public abstract Completion shutdown() Initiate the shut down process on this pool, and return a
| |