Methods Summary |
---|
public synchronized void | freeInstance(java.lang.Object obj)Add an instance of the given object to the pool
// Make sure the object is of the correct type.
// Remove safety. -sb
// if (objectType.isInstance(obj))
// {
freeStack.addElement(obj);
// }
// else
// {
// throw new IllegalArgumentException("argument type invalid for pool");
// }
|
public synchronized java.lang.Object | getInstance()Get an instance of the given object in this pool
// Check if the pool is empty.
if (freeStack.isEmpty())
{
// Create a new object if so.
try
{
return objectType.newInstance();
}
catch (InstantiationException ex){}
catch (IllegalAccessException ex){}
// Throw unchecked exception for error in pool configuration.
throw new RuntimeException(XMLMessages.createXMLMessage(XMLErrorResources.ER_EXCEPTION_CREATING_POOL, null)); //"exception creating new instance for pool");
}
else
{
// Remove object from end of free pool.
Object result = freeStack.lastElement();
freeStack.setSize(freeStack.size() - 1);
return result;
}
|
public synchronized java.lang.Object | getInstanceIfFree()Get an instance of the given object in this pool if available
// Check if the pool is empty.
if (!freeStack.isEmpty())
{
// Remove object from end of free pool.
Object result = freeStack.lastElement();
freeStack.setSize(freeStack.size() - 1);
return result;
}
return null;
|