public class BoundedBlockingPool<T> extends AbstractLifeCycle implements BlockingPool<T>
Pool.Dispose<T>, Pool.Validator<T>start| 构造器和说明 |
|---|
BoundedBlockingPool(int initSize,
BlockingQueue<T> queue,
ObjectFactory<T> factory,
Pool.Validator<T> validator,
Pool.Dispose<T> dispose) |
BoundedBlockingPool(int initSize,
int maxSize,
ObjectFactory<T> factory,
Pool.Validator<T> validator,
Pool.Dispose<T> dispose) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
cleanup() |
protected void |
destroy() |
T |
get()
Returns an instance from the pool.
|
protected void |
init() |
void |
put(T t)
Inserts the specified element into this queue, waiting if necessary for
space to become available.
|
boolean |
put(T t,
long timeout,
TimeUnit unit)
Inserts the specified element into this queue, waiting up to the
specified wait time if necessary for space to become available.
|
void |
release(T t)
Releases the object and puts it back to the pool.
|
int |
size() |
T |
take()
Returns an instance of type T from the pool.
|
T |
take(long time,
TimeUnit unit)
Returns an instance of type T from the pool, waiting up to the specified
wait time if necessary for an object to become available..
|
isStarted, isStopped, start, stoppublic BoundedBlockingPool(int initSize,
int maxSize,
ObjectFactory<T> factory,
Pool.Validator<T> validator,
Pool.Dispose<T> dispose)
public BoundedBlockingPool(int initSize,
BlockingQueue<T> queue,
ObjectFactory<T> factory,
Pool.Validator<T> validator,
Pool.Dispose<T> dispose)
public T get()
PoolInterruptedException which might be thrown when the
thread waits for an object to become available.
If the call is a non-blocking one, the call returns immediately
irrespective of whether an object is available or not. If any object is
available the call returns it else the call returns null.
The validity of the objects are determined using the Validator interface,
such that an object o is valid if Validator.isValid(o) == truepublic T take() throws InterruptedException
BlockingPooltake 在接口中 BlockingPool<T>InterruptedExceptionpublic T take(long time, TimeUnit unit) throws InterruptedException
BlockingPooltake 在接口中 BlockingPool<T>time - amount of time to wait before giving up, in units of unitunit - a TimeUnit determining how to interpret the timeout parameterInterruptedException - if interrupted while waitingpublic void release(T t)
Poolpublic void put(T t) throws InterruptedException
BlockingPoolput 在接口中 BlockingPool<T>t - the element to addInterruptedException - if interrupted while waitingpublic boolean put(T t, long timeout, TimeUnit unit) throws InterruptedException
BlockingPoolput 在接口中 BlockingPool<T>t - the element to addtimeout - how long to wait before giving up, in units of unitunit - a TimeUnit determining how to interpret the
timeout parametertrue if successful, or false if the specified
waiting time elapses before space is availableInterruptedException - if interrupted while waitingprotected void init()
init 在类中 AbstractLifeCycleprotected void destroy()
destroy 在类中 AbstractLifeCycleCopyright © 2016. All rights reserved.