aspose file tools*
The moose likes Servlets and the fly likes help required on multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "help required on multithreading" Watch "help required on multithreading" New topic
Author

help required on multithreading

sachin_ckd
Greenhorn

Joined: Feb 05, 2001
Posts: 16
i have a problem in multithreading which i am using
> > in my code
> > and i am not getting the path out of it.
> >
> > I have designed the servlets for online
> > examination.But the problem is that
> > only one user can give the exam at a time.
> > i have used two variables to trace score and
> > question number.
> > when one user logs in there is no problem.
> >
> > but in between if other one comes,
> > he gets his first question but his score is
> > incremented with the score of first user.
> > similarly his question.
> >
> > if user1 is on fourth question and his score=40;
> > user2 gets score=50 for his first right answer
> > infact it should be 10;
> >
> > i have incremented the score by 10 for each correct
> > answer.
> > the score and question_no are public variables.
> >
> > the test is for 10 questions and i am calling the
> > same servlet in a loop till the completion.
> > it is offcourse not fiesible to design n servlets
> > for n users.
> > i want the same servlet to be used by all the users.
> >
> > what should i do??
> > I am using jdk1.2.2 and Jsdk 2.0
> >
> > please mail me if you can help me.
> > thank you
> > sachin
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Sachin
Welcome to Javaranch. We have to follow some rules pertaining to names (or User Name) here at Javaranch.

Please refer to the Official policy on registered names at this link here

In the simplest of terms you will have to create a new User ID discarding the older one as soon as possible.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Hi,
I guess you have to make use of HttpSessions. This area is adequately addressed in our servlets forum.
I hence move this to the relevant forum.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Check out javax.servlet.http.HttpServletRequest.getSession() and javax.servlet.http.HttpSession.setAttribute(String, Object).
Also, never use non-final member or static variables in a servlet unless you know exactly what you're doing. Servlets are multi-threaded! State is generally stored in the request or session objects.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help required on multithreading