struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Afshartous <>
Subject DataSource enhancement: reclaiming closed connections
Date Fri, 02 Feb 2001 18:45:48 GMT

I've started to sketch out an enhancement to the GenericDataSource
that will reclaim connections that an app forgot to close.  
My current design is to add an inner class (below) to the
GenericDataSource class.  Essentially the GenericDataSource
will have a daemon thread that periodically checks for idle

Naturally, since this is my first attempt at Struts development I
have some questions and thoughts:

 - it occurs to me that simply returning idle connections to the
   pool may not be safe.  What if the original thread that requested 
   the connection starts to use it again while some other thread 
   is currently using the connection.  Maybe the idle connection
   should be destroyed and a new one created ?  

 - i'm not sure how to go about logging errors from the
   GenericDataSource class, please advise.

 - configurable options:  connectionTimeout 
Thanks for any comments.  


    private class ConnectionCollector implements Runnable {

        public void run () {
            // look for Connections that are not being used
            Date currentTime = new Date();
            for (int i = 0; i < usedConnections.size(); i++) {
                GenericConnection conn = (GenericConnection) 
                if ((timeDifference(currentTime, conn.getLastAccessTime()
                  >= connectionTimeout) {
                    try {
                    } catch (SQLException e) { 
                        log("Exception closing Connection");}

View raw message