public class StackKeyedObjectPool<K,V> extends BaseKeyedObjectPool<K,V> implements KeyedObjectPool<K,V>
构造器和说明 |
---|
StackKeyedObjectPool()
Create a new pool using no factory.
|
StackKeyedObjectPool(int max)
Create a new pool using no factory.
|
StackKeyedObjectPool(int max,
int init)
Create a new pool using no factory.
|
StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory)
Create a new
SimpleKeyedObjectPool using
the specified factory to create new instances. |
StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory,
int max)
Create a new
SimpleKeyedObjectPool using
the specified factory to create new instances. |
StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory,
int max,
int init)
Create a new
SimpleKeyedObjectPool using
the specified factory to create new instances. |
限定符和类型 | 方法和说明 |
---|---|
void |
addObject(K key)
Create an object using the
factory ,
passivate it, and then placed in the idle object pool. |
V |
borrowObject(K key)
Borrows an object with the given key.
|
void |
clear()
Clears the pool, removing all pooled instances.
|
void |
clear(K key)
Clears the specified pool, removing all pooled instances corresponding to the given
key . |
void |
close()
Close this pool, and free any resources associated with it.
|
java.util.Map<K,java.lang.Integer> |
getActiveCount() |
KeyedPoolableObjectFactory<K,V> |
getFactory() |
int |
getInitSleepingCapacity() |
int |
getMaxSleeping() |
int |
getNumActive()
Returns the total number of instances current borrowed from this pool but not yet returned.
|
int |
getNumActive(K key)
Returns the number of instances currently borrowed from but not yet returned
to the pool corresponding to the given
key . |
int |
getNumIdle()
Returns the total number of instances currently idle in this pool.
|
int |
getNumIdle(K key)
Returns the number of instances corresponding to the given
key currently idle in this pool. |
java.util.Map<K,java.util.Stack<V>> |
getPools() |
int |
getTotActive() |
int |
getTotIdle() |
void |
invalidateObject(K key,
V obj)
Invalidates an object from the pool.
|
void |
returnObject(K key,
V obj)
Returns
obj to the pool under key . |
void |
setFactory(KeyedPoolableObjectFactory<K,V> factory)
已过时。
to be removed in pool 2.0
|
java.lang.String |
toString()
Returns a string representation of this StackKeyedObjectPool, including
the number of pools, the keys and the size of each keyed pool.
|
public StackKeyedObjectPool()
factory
or
may populate the pool using returnObject
before they can be borrowed
.public StackKeyedObjectPool(int max)
factory
or
may populate the pool using returnObject
before they can be borrowed
.max
- cap on the number of "sleeping" instances in the poolStackKeyedObjectPool(KeyedPoolableObjectFactory, int)
,
setFactory(KeyedPoolableObjectFactory)
public StackKeyedObjectPool(int max, int init)
factory
or
may populate the pool using returnObject
before they can be borrowed
.max
- cap on the number of "sleeping" instances in the poolinit
- initial size of the pool (this specifies the size of the container,
it does not cause the pool to be pre-populated.)StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int)
,
setFactory(KeyedPoolableObjectFactory)
public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory)
SimpleKeyedObjectPool
using
the specified factory
to create new instances.factory
- the KeyedPoolableObjectFactory
used to populate the poolpublic StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int max)
SimpleKeyedObjectPool
using
the specified factory
to create new instances.
capping the number of "sleeping" instances to max
factory
- the KeyedPoolableObjectFactory
used to populate the poolmax
- cap on the number of "sleeping" instances in the poolpublic StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int max, int init)
SimpleKeyedObjectPool
using
the specified factory
to create new instances.
capping the number of "sleeping" instances to max
,
and initially allocating a container capable of containing
at least init
instances.factory
- the KeyedPoolableObjectFactory
used to populate the poolmax
- cap on the number of "sleeping" instances in the poolinit
- initial size of the pool (this specifies the size of the container,
it does not cause the pool to be pre-populated.)public V borrowObject(K key) throws java.lang.Exception
borrowObject
在接口中 KeyedObjectPool<K,V>
borrowObject
在类中 BaseKeyedObjectPool<K,V>
key
- the pool keyjava.lang.IllegalStateException
- after close
has been called on this pooljava.lang.Exception
- when makeObject
throws an exceptionjava.util.NoSuchElementException
- when the pool is exhausted and cannot or will not return another instancepublic void returnObject(K key, V obj) throws java.lang.Exception
obj
to the pool under key
. If adding the
returning instance to the pool results in maxSleeping
exceeded for the given key, the oldest instance in the idle object pool
is destroyed to make room for the returning instance.returnObject
在接口中 KeyedObjectPool<K,V>
returnObject
在类中 BaseKeyedObjectPool<K,V>
key
- the pool keyobj
- returning instancejava.lang.Exception
- Exceptionpublic void invalidateObject(K key, V obj) throws java.lang.Exception
Invalidates an object from the pool.
By contract, obj
must have been obtained
using borrowObject
using a key
that is
equivalent to the one used to borrow the Object
in the first place.
This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
invalidateObject
在接口中 KeyedObjectPool<K,V>
invalidateObject
在类中 BaseKeyedObjectPool<K,V>
key
- the key used to obtain the objectobj
- a borrowed
instance to be returned.java.lang.Exception
- Exceptionpublic void addObject(K key) throws java.lang.Exception
factory
,
passivate it, and then placed in the idle object pool.
addObject
is useful for "pre-loading" a pool with idle objects.addObject
在接口中 KeyedObjectPool<K,V>
addObject
在类中 BaseKeyedObjectPool<K,V>
key
- the key a new instance should be added tojava.lang.Exception
- when KeyedPoolableObjectFactory.makeObject(K)
fails.java.lang.IllegalStateException
- when no factory
has been set or after close()
has been called on this pool.public int getNumIdle()
getNumIdle
在接口中 KeyedObjectPool<K,V>
getNumIdle
在类中 BaseKeyedObjectPool<K,V>
public int getNumActive()
getNumActive
在接口中 KeyedObjectPool<K,V>
getNumActive
在类中 BaseKeyedObjectPool<K,V>
public int getNumActive(K key)
key
.getNumActive
在接口中 KeyedObjectPool<K,V>
getNumActive
在类中 BaseKeyedObjectPool<K,V>
key
- the key to querykey
currently borrowed in this poolpublic int getNumIdle(K key)
key
currently idle in this pool.getNumIdle
在接口中 KeyedObjectPool<K,V>
getNumIdle
在类中 BaseKeyedObjectPool<K,V>
key
- the key to querykey
currently idle in this poolpublic void clear()
clear
在接口中 KeyedObjectPool<K,V>
clear
在类中 BaseKeyedObjectPool<K,V>
public void clear(K key)
key
.clear
在接口中 KeyedObjectPool<K,V>
clear
在类中 BaseKeyedObjectPool<K,V>
key
- the key to clearpublic java.lang.String toString()
toString
在类中 java.lang.Object
public void close() throws java.lang.Exception
Calling addObject
or borrowObject
after invoking
this method on a pool will cause them to throw an IllegalStateException
.
close
在接口中 KeyedObjectPool<K,V>
close
在类中 BaseKeyedObjectPool<K,V>
java.lang.Exception
- deprecated: implementations should silently fail if not all resources can be freed.@Deprecated public void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws java.lang.IllegalStateException
factory
the pool uses
to create new instances.
Trying to change the factory
after a pool has been used will frequently
throw an UnsupportedOperationException
.setFactory
在接口中 KeyedObjectPool<K,V>
setFactory
在类中 BaseKeyedObjectPool<K,V>
factory
- the KeyedPoolableObjectFactory
used to manage object instancesjava.lang.IllegalStateException
- when the factory cannot be set at this timepublic KeyedPoolableObjectFactory<K,V> getFactory()
KeyedPoolableObjectFactory
used by this pool to manage object instances.public java.util.Map<K,java.util.Stack<V>> getPools()
public int getMaxSleeping()
each
pool.public int getInitSleepingCapacity()
public int getTotActive()
public int getTotIdle()
public java.util.Map<K,java.lang.Integer> getActiveCount()