It's not a secret anymore!*
The moose likes Servlets and the fly likes Messed up response to calls to same servlet with different parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Messed up response to calls to same servlet with different parameters" Watch "Messed up response to calls to same servlet with different parameters" New topic
Author

Messed up response to calls to same servlet with different parameters

James Joyce
Greenhorn

Joined: Oct 30, 2002
Posts: 3
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Joyce
Greenhorn

Joined: Oct 30, 2002
Posts: 3
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?
James Joyce
Greenhorn

Joined: Oct 30, 2002
Posts: 3
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Messed up response to calls to same servlet with different parameters
 
Similar Threads
Why do I have to type in twice to log in with basic authentication?
Access denied even the same domain
Picking up parameters in the URL
Apache-Tomcat Integration Problem: only works locally.
where to map the domain name in Tomcat?