Methods Summary |
---|
protected void | createAndAddObject()
Object createdObject = null;
if (_totalNumberOfObjects < _maximumSize) {
Object newObject = _helper.create();
_availableObjects.add(newObject);
_totalNumberOfObjects++;
}
if (null != createdObject) {
notifyWaitingGets();
}
return;
|
private java.lang.Object | getLocallyAvailableObject()
// Locks the container while we check for values.
// That way, we don't simultaneously vend the same object
// to two different requests
synchronized (_availableObjects) {
if (!_availableObjects.isEmpty()) {
int lastPosition = _availableObjects.size() - 1;
return _availableObjects.remove(lastPosition);
}
}
return null;
|
public java.lang.Object | getObject()
Object returnValue = null;
while (null == (returnValue = getLocallyAvailableObject())) {
_creator.askForObject();
waitForAvailableObject();
}
return returnValue;
|
private synchronized void | notifyWaitingGets()
notify();
|
public void | returnObject(java.lang.Object object)
if (_helper.isObjectStillValid(object)) {
_availableObjects.add(object);
notifyWaitingGets();
} else {
_helper.dispose(object);
_totalNumberOfObjects--;
}
return;
|
private void | startCreatorThread(java.lang.String poolName)
_creator = new ObjectCreator(this);
Thread creatorThread = new Thread(_creator, poolName + " creation thread");
creatorThread.setPriority(Thread.NORM_PRIORITY - 2);
creatorThread.start();
|
private synchronized void | waitForAvailableObject()
try {
wait();
} catch (InterruptedException e) {/*ignored*/
}
|