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
connections.  

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.  
-- 

        Nick




    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) 
                    usedConnections.elementAt(i);
              
                if ((timeDifference(currentTime, conn.getLastAccessTime()
                  >= connectionTimeout) {
                    try {
                      conn.close();
                    } catch (SQLException e) { 
                        log("Exception closing Connection");}
                }
            }
        }   
    }   

Reply via email to