A word of warning - synchronizing the forward() method does not stop another thread from changing the values of the 'req' and 'res' variables, so you will still get problems if you implement the first solution.
-----Original Message----- From: Altankov Peter [mailto:[EMAIL PROTECTED] Sent: 11 December 2003 16:00 To: Tomcat Users List Subject: RE: response.reset() and forward() ... problematic? DBCP related? If you go for the SingleThreadModel, try this to workaround your problem: public class TestServlet extends HttpServlet implements SingleThreadModel { ... } However, this interface does not prevent synchronization problems that result from servlets accessing shared resources such as static class variables or classes outside the scope of the servlet and moreover its depricated.(http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/javax /servlet/SingleThreadModel.html) In general avoid any global variables in the scope of the servlet class definition unless you know what you are doing. Use method variables instead. If you decide to go for the real problem solution, either declare the req and res objects in the, lets say, doGet method and pass them to the forward method, or keep their declaration in the servlet class but mark the forward method as syncronized (causing threads to enter it one by one). Here are your hnt snipplets: // the workaround public class TestServlet extends HttpServlet { private HttpServletRequest req; private HttpServletResponse res; [...] public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { [.....] forward("whatever"); } protected synchronized void forward(String s) { [.. Here is where you refer the global req and res objects ..] [.. but its safe, since the method is marked as synchronized ..] } } -- Or -- // some real solution public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpServletRequest req; HttpServletResponse res; [....] forward("whatever", req, res); } protected void forward(String s, HttpServletRequest req, HttpServletResponse res) { [...] } } I hope this helps. -----Original Message----- From: Philipp Taprogge [mailto:[EMAIL PROTECTED] Sent: 11 Декември 2003 г. 16:28 To: Tomcat Users List Subject: Re: response.reset() and forward() ... problematic? DBCP related? Hi! Antonio Fiol Bonnín wrote: > My guess: > > req and res are attributes of the Servlet, like in: > public class TestServlet extends HttpServlet { > private HttpServletRequest req; > private HttpServletResponse res; > [...] > } > > So you are calling "forward(s)" for a request once req and res have > been > overwritten by another request. Hmm... Im a bit lost here... could anyone perhaps be so kind and post a code snipplet of how a thread safe use of a Servlet's request and response attribute could look like? I have not been working with Servlets for too long and I worried I might run into the same problem. Thanks in advance Phil -- "I love deadlines, I love the whooshing noise they make as they go by" - Douglas Adams --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
