Hi, I'm not quite sure if this question belongs here or to tomcat/apache forum but I think the problem is somehow servlet related so i post it here. We are facing a very strange problem on our production server. We have a servlet that recieves a couple of parameters and returns the page contents based on those parameters. Now, if two users call the servlet with their own (different) parameters, sometime the result for one user goes to another one and vice versa. For example, if user 1 calls : http://www.mydomain.com/servlet/DynamicPageBuild?siteID=577&categoryID=69&catName= and user 2 calls (note the difference in parameters) : http://www.mydomain.com/servlet/DynamicPageBuild?siteID=781&categoryID=54&catName= SOMETIMES the result of first request ends up going to user 2's browser or vice versa! We're using TOMCAT 3.2.3 and mod-jk. Anyone PLEASE any ideas of why this is happening?
Two possibilities come to mind: 1. The server really is getting confused across the two requests (a threading issue perhaps?). Or perhaps one or more of your servlets has theading issues. 2. Some "helpful" server somewhere along the line is caching the results of your page. We ran into the latter scenario at a previous job where AOL servers where caching the results of the pages and serving up results for one customer to another. hth, bear
Thanks for the quick reply. Second option looks likely in first look. But then, the URL is different each time (parameters are different) so no server in-between the client and server should cache it, or at least wouldn't send a wrong URL to the request... As for the first option... The servlet itself doesn't do anything extra ordinary with threads etc, it just reads stuff from database and constructs the page basically. Does anyone else have any experience like this with tomcat? would it really get confused when simultaneous (sort of) requests come along?
Joined: Oct 30, 2002
Thanks for the hint bear. That was right, it was a threading issue. The instance variables are mixed up when you have multiple threads. We moved them all into local method variables and it was solved. Alternatively you can declare them synchronized but I believe that it affects perfomance.
Glad to have helped point you in a helpful direction. And yes, since servlets are shared resources, instance variables are a recipe for trouble. Avoiding them is the best policy. Synchonization would create critical sections that block each other's execution, and probably wouldn't solve your problems anyways since you would still only be able to store one set of data values at a time even if you restrict simultaneous access to them. bear