tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakarta Tomcat Newsgroup (@Basebeans.com) <jakarta-...@basebeans.com>
Subject Re: Commons DBCP and closing connections
Date Sat, 24 Aug 2002 03:25:10 GMT
Subject: Re: Commons DBCP and closing connections
From: Matt Raible <matt@raibledesigns.com>
 ===
I changed my closeConnection method (see below).  It seems to work better
(no close connection error), but I am wondering about the open connections
to mysql.  When I monitor them (show status; watch Threads_connected), there
are 3 at first (I'm guessing from my monitor connection, JDBCRealm and
Connection pool).  It gets up to 5, how can I tell if connection pooling is
working?  Especially since my open connection says "non-pooled?"

    
    /** Closes a connection from the connection pool */
    public void closeConnection(Connection con) throws
ServiceLocatorException
    {
        try {
            con.close();
        } catch (SQLException sqle) {
            logger.error("SQLException: " + sqle.getMessage());
            throw new ServiceLocatorException(sqle);
        } finally {
            //if (!con.isClosed()) {
                // try again
                try {
                    if (!con.isClosed()) {
                        con.close();
                    }
                } catch (SQLException csqle) {
                    // ignore
                }
            //}
        }
    }

Thanks,

Matt

On 8/23/02 9:03 PM, in article
mailman.1030158300.17127.jakarta_tomcat@basebeans.com, "Andrew Conrad"
<andrewconrad@attbi.com> wrote:

> That's what I saw.
> 
> - Andrew
> 
>> -----Original Message-----
>> From: Peter Davison [mailto:peterdavison@rogers.com]
>> Sent: Friday, August 23, 2002 10:56 PM
>> To: Tomcat Users List
>> Subject: Re: Commons DBCP and closing connections
>> 
>> 
>> Correct me if I'm wrong but if the first con.close() call
>> succeeds your code will still execute the second con.close()
>> call in the finally block won't it?
>> 
>> Closing the connection won't necessarily dereference the
>> "con" variable, so it's trying to close a connection that is
>> already closed, which would explain the exception you're getting.
>> 
>> P.
>> 
>> On Fri, 23 Aug 2002 19:10:09 -0700
>> Jakarta Tomcat Newsgroup (@Basebeans.com)
>> <jakarta-tom@basebeans.com> wrote:
>> 
>>> Subject: Commons DBCP and closing connections
>>> From: Matt Raible <matt@raibledesigns.com>
>>>  ===
>>> I am trying to upgrade from using Tyrex 0.9.7 to DBCP (from
>> Struts 1.1 
>>> b2) - and I have the following method that used to work fine:
>>> 
>>>     /** Closes a connection from the connection pool */
>>>     public void closeConnection(Connection con) throws
>>> ServiceLocatorException
>>>     {
>>>         try {
>>>             con.close();
>>>         } catch (SQLException sqle) {
>>>             logger.error("SQLException: " + sqle.getMessage());
>>>             throw new ServiceLocatorException(sqle);
>>>         } finally {
>>>             if (con != null) {
>>>                 // try again
>>>                 try {
>>>                     con.close();
>>>                 } catch (SQLException csqle) {
>>>                     // ignore
>>>                 }
>>>             }
>>>         }
>>>     }
>>> 
>>> But now it causes a "connection closed" error??  I thought when you
>>> were using a connection pool, "closing" the connection just
>> releases 
>>> it back to the pool.  Am I doing this right??
>>> 
>>> Matt
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <mailto:tomcat-user-> unsubscribe@jakarta.apache.org>
>>> For 
>> additional commands,
>> e-mail: 
>>> <mailto:tomcat-user-help@jakarta.apache.org>
>>> 
>> 
>> 
>> --
>> Peter Davison
>> peterdavison@rogers.com
>> 
>> Don't everyone thank me at once!
>> -- Han Solo
>> 
>> --
>> To unsubscribe, e-mail:
>> <mailto:tomcat-user-> unsubscribe@jakarta.apache.org>
>> For 
>> additional commands,
>> e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message