T
- public class Pool<T> extends java.lang.Object implements java.lang.AutoCloseable, Dumpable
ThreadLocal
cache of the last release entry.
When the method close()
is called, all Closeable
s in the pool
are also closed.
Modifier and Type | Class and Description |
---|---|
class |
Pool.Entry |
static class |
Pool.StrategyType
The type of the strategy to use for the pool.
|
Dumpable.DumpableContainer
Constructor and Description |
---|
Pool(Pool.StrategyType strategyType,
int maxEntries)
Construct a Pool with a specified lookup strategy and no
ThreadLocal cache. |
Pool(Pool.StrategyType strategyType,
int maxEntries,
boolean cache)
Construct a Pool with the specified thread-local cache size and
an optional
ThreadLocal cache. |
Modifier and Type | Method and Description |
---|---|
Pool.Entry |
acquire()
Acquire an entry from the pool.
|
Pool.Entry |
acquire(java.util.function.Function<Pool.Entry,T> creator)
Utility method to acquire an entry from the pool,
reserving and creating a new entry if necessary.
|
Pool.Entry |
acquireAt(int idx)
Deprecated.
No longer supported. Instead use a
Pool.StrategyType to configure the pool. |
void |
close() |
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
int |
getClosedCount() |
int |
getIdleCount() |
int |
getInUseCount() |
int |
getMaxEntries() |
int |
getMaxMultiplex() |
int |
getMaxUsageCount()
Get the maximum number of times the entries of the pool
can be acquired.
|
int |
getReservedCount() |
boolean |
isClosed() |
boolean |
release(Pool.Entry entry)
This method will return an acquired object to the pool.
|
boolean |
remove(Pool.Entry entry)
Remove a value from the pool.
|
Pool.Entry |
reserve()
Create a new disabled slot into the pool.
|
Pool.Entry |
reserve(int allotment)
Deprecated.
Use
reserve() instead |
void |
setMaxMultiplex(int maxMultiplex) |
void |
setMaxUsageCount(int maxUsageCount)
Change the max usage count of the pool's entries.
|
int |
size() |
java.lang.String |
toString() |
java.util.Collection<Pool.Entry> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, named
public Pool(Pool.StrategyType strategyType, int maxEntries)
ThreadLocal
cache.strategyType
- The strategy to used for looking up entries.maxEntries
- the maximum amount of entries that the pool will accept.public Pool(Pool.StrategyType strategyType, int maxEntries, boolean cache)
ThreadLocal
cache.strategyType
- The strategy to used for looking up entries.maxEntries
- the maximum amount of entries that the pool will accept.cache
- True if a ThreadLocal
cache should be used to try the most recently released entry.public int getReservedCount()
public int getIdleCount()
public int getInUseCount()
public int getClosedCount()
public int getMaxEntries()
public int getMaxMultiplex()
public final void setMaxMultiplex(int maxMultiplex)
public int getMaxUsageCount()
public final void setMaxUsageCount(int maxUsageCount)
maxUsageCount
- the max usage count.@Deprecated public Pool.Entry reserve(int allotment)
reserve()
insteadPool.Entry.enable(Object, boolean)
method called or be removed via Pool.Entry.remove()
or
remove(Pool.Entry)
.allotment
- the desired allotment, where each entry handles an allotment of maxMultiplex,
or a negative number to always trigger the reservation of a new entry.getMaxEntries()
entries, or the allotment has already been reservedpublic Pool.Entry reserve()
Pool.Entry.enable(Object, boolean)
method called or be removed via Pool.Entry.remove()
or
remove(Pool.Entry)
.getMaxEntries()
entries@Deprecated public Pool.Entry acquireAt(int idx)
Pool.StrategyType
to configure the pool.idx
- the index of the entry to acquire.public Pool.Entry acquire()
public Pool.Entry acquire(java.util.function.Function<Pool.Entry,T> creator)
creator
- a function to create the pooled value for a reserved entry.public boolean release(Pool.Entry entry)
entry
- the value to return to the poolremove(Pool.Entry)
and the object contained by the entry should be disposed.java.lang.NullPointerException
- if value is nullpublic boolean remove(Pool.Entry entry)
entry
- the value to removepublic boolean isClosed()
public void close()
close
in interface java.lang.AutoCloseable
public int size()
public java.util.Collection<Pool.Entry> values()
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Dumpable
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 1995–2021 Webtide. All rights reserved.