aspose file tools*
The moose likes Servlets and the fly likes threading issues in JSP and Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "threading issues in JSP and Servlets" Watch "threading issues in JSP and Servlets" New topic
Author

threading issues in JSP and Servlets

sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
It is written in books that there is only one service method which handles all the requests.here is my question.If I am creating a web site with high volume traffic then do I have to synchronize all the getter and setter methods.I mean suppose that there is a login page.A user enters his/her login name and password.On the server side we are using the setProperty action tag of the JSP.As soon as we do this the instance variables of the bean get set.But suppose another using is using getProperty action of the bean then don't you think there are chances that it might display the results of the first user.How is this handled?
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Hai Sanjay,
I think the service method is excuted in synchronized state.You can chage the situation using the attribute isThreadSafe in jsp or implementing SingleThreadModel interface in your servlet
[This message has been edited by Anoop Krishnan (edited July 13, 2001).]


I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
I don't want to use the singleThreadModel interface as this will slow down the application tremendously.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hi Sanj,
Every request to the service method of a servlet/JSP creates a new thread. Suppose, there are two simultaneous requests come, definitely there will be two concurrent threads will be running in that Servlet/Jsp Context.
You didn't mention from where you are gettin the values for getProperty.
if your are using a bean which access a database for validation,
there is no need of synchronization since most dbms has concurrent thread handling mechanisms.
If you are not using a database, you should use the synchronized method for the appropriate methods.

Thanks
Binu

Sarath Mohan
sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
dear Binu and Anoop
Thanks a lot for ur reply.Both of you have helped me a lot but I have this problem still in my mind.Say there are two people logging at the same time.There names are Anoop Krishnan and Binu Kavumkal.say both of them enter the user name and password at the same time and this request is going to a jsp page.Now that jsp page has an action attribute as say
<jsp:setProperty name="classnameid" property="*">
this will set the name and password property of the bean.Now if two people are setting it at the same time don't you think that both the getter and setter methods should be synchronized.I hope you understans my problem now.
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Dear Sanj,
If you use all of your variables & objects locally in the service method you need not bother about thread issues
eg
<%
String userName=request.getParameter("username");
String password=request.getParameter("password");
%>
if you do something with a class variable.then you will have problems
eg
<%!
String userName;
String password
%>
<%
userName=request.getParameter("username");
password=request.getParameter("password");
%>
because here two different threads are modifying the same references
Am i wright ?
 
Don't get me started about those stupid light bulbs.
 
subject: threading issues in JSP and Servlets