java.lang.Object
org.roller.business.castor.DatabasePool
- All Implemented Interfaces:
- java.lang.Runnable
- public class DatabasePool
- extends java.lang.Object
- implements java.lang.Runnable
A class for preallocating, recycling, and managing connections.
Adapted for handling JDO Database objects rather than connections.
Taken from Core Servlets and JavaServer Pages
from Prentice Hall and Sun Microsystems Press,
http://www.coreservlets.com/.
© 2000 Marty Hall; may be freely used or adapted.
|
Constructor Summary |
DatabasePool(JDO jdo,
int initialConnections,
int maxConnections,
boolean waitIfBusy)
|
mJDO
protected transient JDO mJDO
maxConnections
private int maxConnections
waitIfBusy
private boolean waitIfBusy
availableConnections
private java.util.Vector availableConnections
busyConnections
private java.util.Vector busyConnections
connectionPending
private boolean connectionPending
DatabasePool
public DatabasePool(JDO jdo,
int initialConnections,
int maxConnections,
boolean waitIfBusy)
throws java.lang.Exception
getConnection
public Database getConnection()
throws java.lang.Exception
makeBackgroundConnection
private void makeBackgroundConnection()
run
public void run()
- Description copied from interface:
java.lang.Runnable
- This method will be called by whoever wishes to run your class
implementing Runnable. Note that there are no restrictions on what
you are allowed to do in the run method, except that you cannot
throw a checked exception.
- Specified by:
run in interface java.lang.Runnable
makeNewConnection
private Database makeNewConnection()
throws java.lang.Exception
free
public void free(Database connection)
totalConnections
public int totalConnections()
closeAllConnections
public void closeAllConnections()
- Close all the connections. Use with caution:
be sure no connections are in use before
calling. Note that you are not required to
call this when done with a DatabasePool, since
connections are guaranteed to be closed when
garbage collected. But this method gives more control
regarding when the connections are closed.
closeConnections
private void closeConnections(java.util.Vector connections)
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object
- Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method
never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string
concatenation with this object. If the result is
null, string concatenation will instead
use "null".
The default implementation returns
getClass().getName() + "@" +
Integer.toHexString(hashCode()).