Hello everybody

I want to check the syntax to use when storing my connection pool in the
ServletContext. I had problems with my singleton pool-object so I decided to
try this approach mentioned in recent postings.

It works definitely better than my other one, but there are some things that
make me wonder. At the moment I am doing getAttribute() twice, is that good
or bad? With this approach I can do everything in local variables in each
method, but since I really should synchronize the calls for getAttribute()
anyway I guess I could just as well make the pool a class variable, thereby
reducing the method calls I have to do. Or what do you think?

This is what I do right now:

public class SearchServlet extends HttpServlet {

  public void init (ServletConfig config) throws ServletException  {
    super.init(config);

    DbConnectionBroker deebs = (DbConnectionBroker)
getServletContext().getAttribute("cons");
    if(deebs == null){

        // do the driver stuff

        deebs = new
DbConnectionBroker(dbD,dbS,dbL,dbP,minC,maxC,logF,maxCT);
        getServletContext().setAttribute("cons", deebs);
    }
  }

  public void doPost (HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException  {

    DbConnectionBroker myBroker = (DbConnectionBroker)
getServletContext().getAttribute("cons");
    Connection myCon = myBroker.getConnection();

    // do the database stuff

    myBroker.freeConnection(myCon);

    // do the output stuff
  }
}


I welcome all comments.

Thankful for any help,
/Micael

Micael K�llman  [EMAIL PROTECTED] 018-167709

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to