tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john-paul delaney ...@justatest.com>
Subject JNDI DataSource - need to synchronize?
Date Sun, 07 Sep 2003 11:18:51 GMT
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.


Mime
View raw message