java对象池初步浏览ObjectPool接口
常用的接口
ObjectPool<T>
获取对象
T borrowObject() throws Exception, NoSuchElementException,
IllegalStateException;
清除
void clear() throws Exception, UnsupportedOperationException;
关闭
void close();
激活的数量
int getNumActive();
空闲的数量
int getNumIdle();
使不可用
void invalidateObject(T obj) throws Exception;
default void invalidateObject(final T obj, final DestroyMode destroyMode) throws Exception {
invalidateObject(obj);
}
返回对象
void returnObject(T obj) throws Exception;
引用池的代码
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.11.1</version>
</dependency>