S
Scotchy
I have a probably simple question from which I have been unable to answer.
If servlets are reusable are they thread safe? For example if I am
processing 5 customers all at the same time using the same servlet do I need
to be careful what I store in vars within a class object? Given the pseudo
code below...
public class multiuserservlet extends servlet
{
HttpRequest req=null;
String username="";
public multiUserServlet () {
//Empty constructor
}
public multiUserServlet (HttpRequest request,String uname) {
this.req=request;
this.username=uname;
}
public void DoSomething() {
//Look at the req object here
//do something with username
username+=" Buddy";
}
public void DoSomething(HttpRequest req) {
//Look at the req object here
//do something with username
username+=" Buddy";
}
}
Which DoSomething method is safer or does it matter? I have read numerous
JSP books some of them say it is not safe but doesn't describe why it is not
safe. Is it a question of context switching within the JSP engine? BTW I
am using the latest version of Apache,Tomcat, and J2SE
Thanks for your help
Scotchy
If servlets are reusable are they thread safe? For example if I am
processing 5 customers all at the same time using the same servlet do I need
to be careful what I store in vars within a class object? Given the pseudo
code below...
public class multiuserservlet extends servlet
{
HttpRequest req=null;
String username="";
public multiUserServlet () {
//Empty constructor
}
public multiUserServlet (HttpRequest request,String uname) {
this.req=request;
this.username=uname;
}
public void DoSomething() {
//Look at the req object here
//do something with username
username+=" Buddy";
}
public void DoSomething(HttpRequest req) {
//Look at the req object here
//do something with username
username+=" Buddy";
}
}
Which DoSomething method is safer or does it matter? I have read numerous
JSP books some of them say it is not safe but doesn't describe why it is not
safe. Is it a question of context switching within the JSP engine? BTW I
am using the latest version of Apache,Tomcat, and J2SE
Thanks for your help
Scotchy