tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: dbcp, initCtx.close()??
Date Fri, 12 Sep 2003 18:22:23 GMT

As long as you keep the initial context reference inside a method, and
not a class member variable, you'll be fine, especially if all you're
doing is just getting one resource (the DataSource) out of it.  The
initial context will then go out of scope and be garbage collected,
freeing up its resources, when the method exits.

If you have the context as a member variable or in a long-lived method,
closing it is a good idea.

Regardless, closing it can't do harm.  It doesn't do that much good
either, but at least it can't do harm ;)

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Phillip Qin []
>Sent: Friday, September 12, 2003 2:20 PM
>To: 'Tomcat Users List'
>Subject: RE: dbcp, initCtx.close()??
>I close Context right after I get DataSource. Then I can still do
>dataSource.getConnection(). So this close will not connection.
>-----Original Message-----
>From: Paul []
>Sent: September 12, 2003 2:19 PM
>To: Tomcat Users List
>Subject: dbcp, initCtx.close()??
>Tomcat docs advise following code for openning a dbcp connection:
>// Obtain our environment naming context
>Context initCtx = new InitialContext();
>Context envCtx = (Context)initCtx.lookup("java:comp/env");
>// Look up our data source
>DataSource ds = (DataSource)envCtx.lookup("jdbc/eplResrc");
>However, the Tomcat docs do not say anything about closing initCtx.
>this need to be explicitly closed in developer code?  Will
>create memory leaks?  The reason i ask is because i came across example
>closing context in that Wrox book, "Professional Apache Tomcat", as
>initCtx.close();  // closed after conn is closed (see Wrox, p.327)
>-paul lomack

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

View raw message