Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threading issues in JSP and Servlets

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to use the singleThreadModel interface as this will slow down the application tremendously.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic