Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning wrong response 1

Status
Not open for further replies.

cpope

Programmer
Jul 7, 2000
58
US
I am wondering if anyone has experienced a similar problem with websphere. We have a servlet that takes in an account number as a querystring parameter. Sometimes a different account gets pulled up. It is like the response for another request gets posted back to the browser. Is it possible for threads to get crossed ?? This only happens once in a while, it is not consistent, and we are unable to re-create it. (if we click the link a second time, the proper account gets brought up).
 
The only thing I can think of is with code like this
Code:
SomeServlet extends HttpServlet {
  private MyQueryResults mq;

  doPost (HttpS... ) {
    --Do a query on the account number--
    --and place into MyQueryResults--
  }
}

This is a bad practice because you have not protected the query results from the multithreaded environment of a servlet by having them as a global variable. So if request 1 comes in and starts a query which takes 10 seconds to return, while request 2 comes in .1 sec later and takes 1 second to return, the results returned to both request 1 and request 2 will be exactly the same.
If you do have global variables, you may want to localize them inside of your doPost/doGet methods. It will remove that problem.

That's the only reason I can give for this happening to you.

Hope it helps.
 
Thanks... we had some variables declared outside the post/get methods... I moved all variable declarations to inside the method. We will give it a shot and hopefully it will solve our problem ! I am sorry for posting it in the websphere forum, I thought it was a server issue! Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top