Methods Summary |
---|
public Type | aquire()
// fail if writelock is aquired
if (this.readLock.tryLock()) {
try {
if (this.isDestroyed)
throw new IllegalStateException(
"The pool has already been closed");
if (this.pool.isEmpty())
return this.factory.getInstance();
return this.pool.pop();
} finally {
this.readLock.unlock();
}
}
throw new IllegalStateException("The pool has already been closed");
|
public void | destroy()
this.writeLock.lock();
try {
if (this.isDestroyed)
return;
this.isDestroyed = true;
LOG.info("Destroy all elements in the pool -- poolsize: "+this.pool.size());
for (Type type : this.pool) {
this.factory.destroyInstance(type);
}
this.pool.clear();
} finally {
this.writeLock.unlock();
}
|
public boolean | expires()
return false;
|
public long | getExpireTime()
return 0;
|
public int | getSize()
return this.size;
|
public void | release(Type type)
// fail if writelock is aquired
if (this.readLock.tryLock()) {
try {
if (this.pool.size() < this.size && !this.isDestroyed)
this.pool.push(type);
else
this.factory.destroyInstance(type);
} finally {
this.readLock.unlock();
}
return;
}
// enable object need to be destoryed
this.factory.destroyInstance(type);
|