Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 14304 invoked from network); 7 Sep 2003 08:13:09 -0000 Received: from unknown (HELO jemoserver) (62.3.127.84) by daedalus.apache.org with SMTP; 7 Sep 2003 08:13:09 -0000 Received: from jemoserver ([192.168.2.3]) by jemoserver (JAMES SMTP Server 2.2.0a10) with SMTP ID 119 for ; Sun, 7 Sep 2003 09:13:15 +0100 (BST) Message-ID: <00ab01c37517$e3032e80$0302a8c0@jemoserver> From: "Marco Tedone" To: "Tomcat Users List" References: Subject: Re: JNDI DataSource - need to synchronize? Date: Sun, 7 Sep 2003 09:13:14 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Well, to be sure, put your variables inside the methods. This way, your data will be safe. One idea would be to create objects when you need them, and to close them when you've finished. Marco ----- Original Message ----- From: "john-paul delaney" To: "Tomcat Users List" Sent: Sunday, September 07, 2003 12:18 PM Subject: JNDI DataSource - need to synchronize? > Hello List... > > Some coding help please. Following earlier advice on this list and the TC datasource how-to, I've now got a working test servlet. Basically I declare the Context(s) and DataSource as instance variables, and initialize them in init: > > ======================================================== > Context initContext = null; > Context envContext = null; > DataSource ds = null; > > public void init() throws ServletException { > > try { > initContext = new InitialContext(); > > envContext = (Context) initContext.lookup( > "java:comp/env"); > ds = (DataSource) envContext.lookup( > "jdbc/jpdb"); > } catch (NamingException e) { > > throw new ServletException( > "Couldn't setup JNDI Context/DataSource", e); > > } > } > ========================================================== > > If this is the correct approach, should I be synchronizing the Context(s)/DataSource in the doGet method? If another http request thread closes it's own connection, will it affect the Context or DataSource object of this request? > > Thanks for any clarification, > /j-p. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org >