R
- 资源类型public class ResourcePool<R> extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ResourcePool.IntResourcePool
以固定步长生成的一组数字为资源的资源池对象
|
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.LinkedBlockingQueue<R> |
queue
资源队列
|
Modifier | Constructor and Description |
---|---|
protected |
ResourcePool() |
|
ResourcePool(java.util.Collection<R> resources)
构造方法
|
|
ResourcePool(R... resources) |
Modifier and Type | Method and Description |
---|---|
R |
apply()
(阻塞式)申请当前线程使用的资源对象,不可跨线程使用
InterruptedException 封装到RuntimeException 抛出 |
R |
applyChecked()
(阻塞式)申请当前线程使用的资源对象,不可跨线程使用
|
protected R |
close(R resource)
资源对象放回队列时调用,子类可重写此方法
|
void |
free()
释放当前线程占用的资源对象,放回资源队列
|
protected boolean |
isNestable()
是否允许嵌套
|
protected R |
newResource()
创建一个新的资源对象
|
protected R |
open(R resource)
资源从队形从取出时调用,子类可重写此方法
|
protected ResourcePool()
public ResourcePool(java.util.Collection<R> resources)
resources
- 资源对象集合java.lang.IllegalArgumentException
- 包含null
元素@SafeVarargs public ResourcePool(R... resources)
public final R applyChecked() throws java.lang.InterruptedException
java.lang.InterruptedException
public final R apply()
InterruptedException
封装到RuntimeException
抛出applyChecked()
public final void free()
protected boolean isNestable()
protected R newResource()
protected R open(R resource)
resource
- Copyright © 2019. All rights reserved.