Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am in need of help..this is intersting

 
anand chawla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Just started working on servlets.needed help.
well i m developing a online exams program.
What i need to do is read 40 records from database
which i m doing successfully.But when i run on network
what happens is when two or more persons start the test
if one person answers the first one..the other person gets the second one straightaway.I have a slight idea why this happens..but would like if anyone explains it to me in better way.also what the solution is.
Thanks
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This kind of problem is almost always because you have member variables declared in your Servlet. You must always remember that the Servlet API is multi-threaded - all client requests use the same servlet, and not store chnageable values in member variables, only in local variables or some context which is not shared between Servlets (such as a Session).
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use local variables as Frank suggests or you can also have you servlet implement SingleThreadModel. The servlet container will then create a new instance of the servlet for each request. That is what I did at my first servlet site. It seemed easier than deciding what code had to be syncronized.
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend putting each users data into the session. Just remember to clean out the session when they are done so that the next person to use the computer doesn't get all their answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic