To obtain a connection from the default pool, all you need to do is
write code like this:
 |
 |
 |
 |
DBConnection dbConn = null;
try
{
dbConn = TurbineDB.getConnection();
// Do something with the connection here...
}
catch (Exception e)
{
// Either from obtaining the connection or from your application code.
}
finally
{
try
{
TurbineDB.releaseConnection(dbConn);
}
catch (Exception e)
{
// Error releasing database connection back to pool.
}
}
|
 |
 |
 |
 |
To obtain a connection from another pool, simply pass the name of the other
pool to the TurbineDB:
 |
 |
 |
 |
DBConnection db = TurbineDB.getConnection("mypoolname");
|
 |
 |
 |
 |
You should always make sure to enclose your code within
the try/finally block so that you make sure to always release the connection
back to the pool. If you experience a situation where it seems like your
code locks up after a while and you do not get results back from the browser,
then chances are that you have forgotten to release a connection back to
the pool for some reason. An enhancement to the pooling code would be to
add a background cleanup thread that cleans up connections that have not
been released back to the pool after a determined amount of time. This
does not fix the problem of bad code, but would help in situations where
bad code does manage to find its way into the system.