commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: DBCP status?
Date Mon, 30 Jun 2003 01:24:55 GMT
--- Tim Funk <funkman@joedog.org> wrote:
> David Graham wrote:
> > I am open to designing DBCP in such a way that allows people to plugin
> the
> > behaviors they need including reclaming connections (the Strategy
> pattern
> > may be useful here).  However, DBCP should never provide that
> > functionality out of the box because it implies that Jakarta supports
> poor
> > programming practices.
> > 
> 
> +1 for allowing people to plugin their own "kludge" to reclaim
> connections. 
> In a perfect world we (ok, me) wouldn't need the reclaiming connection
> code. 
> But I still (in fact 3 weeks ago) fall victim to the following cut and
> paste 
> typos, for example:
> 
> Connection con;
> PreparedStatement ps;
> ResultSet rs;
> try {
>     con = magicGetConnection();
>     //stuff
> } catch(...) {
> } finally {
>    try {if (rs!=null){ rs.close(); rs=null; } } catch(Throwable
> ignore){}
>    try {if (ps!=null){ ps.close(); ps=null; } } catch(Throwable
> ignore){}
>    try {if (ps!=null){ con.close(); con=null; } } catch(Throwable
> ignore){}
> }

Well the first mistake here is catching Throwable (a bad idea) and then
ignoring it (a really bad idea).  The second mistake is not factoring this
error prone code into a more maintainable form.  Adding a couple of
methods like:

closeConnection(Connection conn) {
    if (conn != null) {
        try { 
            conn.close(); 
        } catch (SQLException e) { 
            // log e here
        }
    }
}

would have prevented your problem in the first place.

David

> 
> In the above code - I try to use the good practice of try-catch-finally.
> My 
> code works great in the testing environment (of course it should fail in
> 
> stress testing in cases it can be done). The peer review goes great (or
> gets 
> ommitted for some places which don't have that luxury) and the peer
> reviewer 
> also overlooks the leaking connection. Time for production - within
> hours - 
> the site starts acting strange but only intermittently. The reclamation
> of 
> connections keeps the site running and the logging we get allows us to
> say "O 
> crap!" and fix the problem quickly.
> 
> Some of try to use great programming practices but we are mere mortals.
> I am 
> not in favor of haphazardly  yanking connections. But in some
> environments, 
> yanking the connection away from the application may not be that bad of
> a 
> thing.
> 
> 
> -Tim
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message