Sorry I hit the submit button by accident. I use an
Applet to communicate to the servlet and the servlet looks something like this:
public class TestServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
// Receive input data
ObjectInputStream input = new ObjectInputStream(request.getInputStream());
Vector inData = (Vector) input.readObject();
input.close();
// Extract the action
String action = (String) inData.elementAt(0);
Vector outData = null;
// Perform the requested action
if (action.equalsIgnoreCase("GET_STUDENT_INFO")) {
outData = this.getStudentInfo(inData);
}
else if (action.equalsIgnoreCase("GET_TEACHER_INFO")) {
outData = this.getTeacherInfo(inData);
}
// Send output data
response.setContentType("application/x-java-serialized-object");
ObjectOutputStream output = new ObjectOutputStream(response.getOutputStream());
output.writeObject(outData);
output.flush();
output.close();
}
catch (Throwable exception) {
throw new ServletException(exception.getMessage());
}
}
private Vector getStudentInfo(Vector inData) {
Vector studentInfo = new Vector(10);
// Query Student Info
//...
return studentInfo;
}
private Vector getTeacherInfo(Vector inData) {
Vector teacherInfo = new Vector(10);
// Query Teacher Info
//...
return teacherInfo;
}
}
I know that for every call to the doPost method a new
Thread is created to handle the request. But do all threads share the getStudentInfo and getTeacherInfo methods or does each thread have its own copy? I'm going to have multiple people hitting this servlet and I would not be good for performance if the methods were shared and I had to synchronize them.
Any info would be helpful.
Thanks.