Howdy, 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 [mailto:[EMAIL PROTECTED] >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 [mailto:[EMAIL PROTECTED] >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. Does >this need to be explicitly closed in developer code? Will not-closing-it >create memory leaks? The reason i ask is because i came across example of >closing context in that Wrox book, "Professional Apache Tomcat", as >follows: > >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. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]