I have a question about database connection.
In the code below, what happen when one request has just creating a session
for storing the connection, and the another request is about to execute
session.removeAttribute that will kill the session?  Is the session unique
for each request, means that when one user kill connection session will not
affect other user's connection session?  Or all request share the same
connection session?
Is this a good way to maintain connection for each request? Why?

Thank you. I appreciated any input.

Andi Setiyadi

Attached code:

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

   HttpSession session = req.getSession(true);
   Connection conn;

   synchronized(session) {
      conn = (Connection) session.getAttribute("connection");
      if (conn == null)  {
         ConnectionBean cBean = new ConnectionBean();
         conn = cBean.getConnection();
         session.setAttribute("connection", conn);
      }
   }

   // perform some tasks
   ...

   try    {
      if (conn != null)  {
         conn.close();
      }
   }

   catch(Exception e)   {     }

   session.removeAttribute("connection");
}

___________________________________________________________________________
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