Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange problem

 
rajavardhan n
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi list
iam facing a strange problem. When two users are simultaneously acessing the same servlet then both the pages are being displayed to the same user and the other user is getting a blank page.
I haven't used synchronization in my servlets.
This is the case when iam doing database operations in my servlets.
I have tested them on javawebserver2.0 trail version and jrun3.0 evaluation version as a plug in to IIS server.
please clarify me
with regards
rajavardhan
raja_n@satyam.net.in
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this is your problem but...
The service, doGet and doPost methods should not use any instance variables and instead local variables.
That's because there is usually only one instance of a servlet which gets executed by different threads, one per request. Saving state in instance variables of servlets invites problems.
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like the both instances are writing to the same response PrintWriter. For instance, one servlet gets a request, says PrintWriter out = response.getWriter() and then the next instance of the servlet somehow gets a handle on that initial PrintWriter. You're not using a static Writer object or anyting like that are you? Also, I assume that this does not happen when two different servlet are accessed. If this were the case then the problem may lie with your setting for the servlet engine's request dispatcher. Pehaps a peak at the code for servlet in question may shed some light on the problem.
Sean
 
rajavardhan n
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks tony andsean for ur response. I have used instance variables in the servlets. I wrote some methods other than doGet() ot doPost() for that sake made all the variables as instance variables. Once i remove those variables now its working fine. but i still have have a query how both outputs can be redirected to the same user. if iam using instance variables then they should cause inconsistent values but how is it redirecting the output to the same user please shed some light on this tony
thanks
with regards
rajavardhan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic