1
package com.highcharts.export.pool;
3
import java.util.concurrent.LinkedBlockingQueue;
4
import java.util.concurrent.TimeUnit;
7
public class BlockingQueuePool<T> extends AbstractPool<T>{
9
LinkedBlockingQueue<T> linkQueue;
13
* @throws PoolException
16
public BlockingQueuePool(ObjectFactory<T> factory, int number, int maxWait, long retentionTime) throws PoolException {
17
super(factory, number, maxWait, retentionTime);
18
queue = new LinkedBlockingQueue<T>();
19
linkQueue = (LinkedBlockingQueue<T>) queue;
24
public T borrowObject() throws InterruptedException, PoolException {
25
T object = linkQueue.poll(maxWait, TimeUnit.MILLISECONDS);
27
throw new PoolException();
29
poolSize.getAndDecrement();
35
public void returnObject(T object, boolean validate) throws InterruptedException {
40
boolean valid = ( !validate || objectFactory.validate(object)) ? true : false;
43
destroyObject(object);
45
objectFactory.passivate(object);
46
linkQueue.offer(object, maxWait, TimeUnit.MILLISECONDS);
47
poolSize.incrementAndGet();