From tomcat-user-return-86390-apmail-jakarta-tomcat-user-archive=jakarta.apache.org@jakarta.apache.org Thu Dec 11 06:49:41 2003 Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 53793 invoked from network); 11 Dec 2003 06:49:41 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 11 Dec 2003 06:49:41 -0000 Received: (qmail 72387 invoked by uid 500); 11 Dec 2003 06:48:58 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 72366 invoked by uid 500); 11 Dec 2003 06:48:58 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 72351 invoked from network); 11 Dec 2003 06:48:57 -0000 Received: from unknown (HELO loif) (217.126.142.208) by daedalus.apache.org with SMTP; 11 Dec 2003 06:48:57 -0000 Received: from loif ([127.0.0.1] helo=terra.es ident=fiol) by loif with esmtp (Exim 3.36 #1 (Debian)) id 1AUKdI-0001hJ-00 for ; Thu, 11 Dec 2003 07:49:08 +0100 Message-ID: <3FD81362.7070402@terra.es> Date: Thu, 11 Dec 2003 07:49:06 +0100 From: =?ISO-8859-1?Q?Antonio_Fiol_Bonn=EDn?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3 X-Accept-Language: es-es, es, fr-fr, fr, en-gb, en-us, en MIME-Version: 1.0 To: Tomcat Users List Subject: Re: response.reset() and forward() ... problematic? DBCP related? References: <1071099829.7825.167.camel@tigger> In-Reply-To: <1071099829.7825.167.camel@tigger> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Answer included in your text, and at the end. Anthony Presley wrote: >[...] and I'm having a lot of errors, which >scale based on the number of users. For instance, assuming I have >around 10 people working on the system, I will have no errors. As that >number scales, it becomes a huge problem, and lots of error's start >showing up. I've tracked down and squashed most of the DB errors, but >am left with the following quandry: > > It smells like a concurrency problem. >I'm not storing any data in the session, and use forward() ... a lot. >When the following code executes, and I only open one request (ie, I >click on the link to open a new window which fetches a servlet >response), it works flawlessly. When I click more than once, I start >getting forward() errors. > > Smell is getting intense ;-) >Here's some code snippets: > > [... reduced to a minimum, but the problem still there ...] > protected void forward(String s) { > ServletConfig sc = null; > ServletContext sContext = null; > RequestDispatcher rd = null; > > sc = this.getServletConfig(); > sContext = sc.getServletContext(); > rd = sContext.getRequestDispatcher(s); > rd.forward(req, res); > > Hey! Where are you getting "req" and "res" from?!! My guess at the end. >3. I've bumped the response buffer (in the servlet) from 8K to 75K >(75000), which reduces the errors, but they are still present. Is there >a GOOD way to estimate the amount needed? > > No need to increase anything. It might alleviate the problem or even improve performance (??), but not solve anything. >4. Using DBCP 1.0 .... using the latest DBCP (1.1?), seems to reduce >the errors further (1 in 10, approx). I've rewritten the code to ensure >that connections are being opened / closed locally, and quickly. Timing >it shows that the DB connection is pulled from the pool for about 2300 >milli, and the JSP runs for about 2 milli to display. > > Same here. The shorter your DB connections are open, the better, but this will not solve your problem. >I'm not 100% sure yet if the problem persists in the JSP (using a simple >JSP and simple servlet does not cause these problems, however, the >greater the complexity, the higher the likelihood of getting these >errors .... which baffle's me, because rerequesting it shows up fine, >with nothing in the logs) or the servlet. > > But the greater the complexity, the greater your chances to get two users using your servlet concurrently. >Anyone seen this before? I'm about at my wits end. Been refactoring >for a week now, and still it persists. > > Yes. I found it to be a very common mistake. Now you know where the problem lies, you probably already thought of a solution specific to your case. 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. Just in case my English is too bad, and so that the archive is useful for people searching it: - NEVER use object attributes in Servlets, as a rule of thumb. - ALWAYS use local variables instead. If you really cannot follow the above, then: - Make sure that you need ONLY ONE INSTANCE of the object stored in that attribute. - One instance for: all concurrent users, and all successive requests. - Make sure that this instance is THREAD SAFE. - A typical example of this is the use of a logger. - Another example are STATIC attributes, which are, in general, less error-prone in this context. If you really cannot follow any of the above, there is still one solution: - Make sure your servlet "implements SingleThreadModel". This will ensure a different instance is used for all concurrent requests, or that no concurrent requests will occur. Hope that helps. Antonio Fiol --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org