File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Is JSP thread safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is JSP thread safe?" Watch "Is JSP thread safe?" New topic
Author

Is JSP thread safe?

gopi nath
Greenhorn

Joined: Mar 20, 2001
Posts: 3
Hi all,
I have an entry screen which runs into several pages and
I have an object containing all data which is put into session . At the last page only i insert into database using a EJBean method.
I am using JSP, EJB and Weblogic.
The problem i have faced sometimes is:
Sometimes the values in session pass onto diff users.Thats why i have asked is JSP thread safe? And do we need to write some special code to make it thread safe?
Thanks in advance
Gopinath
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hi,
Just go through the <%@ page directiv attributes.
there is an attribute called isThreadSafe.
I think this suffices your requirement
Binu


Sarath Mohan
Ash Rai
Ranch Hand

Joined: Dec 15, 2000
Posts: 34
Hi,
Is it not true that by making it thread safe we can actually slow down the access time for different requests?? I am facing a similar problem...I am using jsp,servlets and java beans for getting information from the user and then populating the database with those. I have used the isThreadsafe=true option. Will my application face a problem like Gopitnath's? If I want to use synchronise keyword instead then which are the code statements that need to be placed in the synchronised block? Is it sufficient to synchronise just the psmt.executeQuery() and executeUpdate() methods only or should I synchronise even the java beans (becoz their get and set methods may be used by multiple users at the same time)?
Please help
Thanks
sathish jayaraman
Greenhorn

Joined: Mar 22, 2001
Posts: 2
Hi,
U have to make the setter and getter methods of the bean also synchronized for threadsafety.
sathish.

Originally posted by Ash Rai:
Hi,
Is it not true that by making it thread safe we can actually slow down the access time for different requests?? I am facing a similar problem...I am using jsp,servlets and java beans for getting information from the user and then populating the database with those. I have used the isThreadsafe=true option. Will my application face a problem like Gopitnath's? If I want to use synchronise keyword instead then which are the code statements that need to be placed in the synchronised block? Is it sufficient to synchronise just the psmt.executeQuery() and executeUpdate() methods only or should I synchronise even the java beans (becoz their get and set methods may be used by multiple users at the same time)?
Please help
Thanks

lokesh reddy
Ranch Hand

Joined: Sep 15, 2000
Posts: 66
Hi gopi,
The jsp page by default is not thread safe, if u want to make it thread safe then you have add the following directive in your jsp page declaration.
<%@ page language="java" isThreadSafe=false%>
Dont think i have put isThreadSafe=false by mistake. You have to make it false, if u want to make ur jsp page thread safe. Bye default the attribute will be true.
If u want to find whats the reason behind it, then i would like to suggest you to go through the jsp specification.
I hope u find this info useful.
Bye.
Loke.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by lokesh reddy:
The jsp page by default is not thread safe, if u want to make it thread safe then you have add [isThreadSafe=false] in your jsp page declaration.

if u want to make it thread safe then you have add [isThreadSafe=false]... it sure looks looks odd when you put it that way
Whether your JSP is treadsafe or not is a consequence of the way you implemented your JSP. Strictly speaking you cannot change that simply by modifying an attribute. JSPs are normally perfectly threadsafe, since your run of the mill JSP does not hold any state (member variables). Generally only when you introduce member variables into the JSP object does it become thread-unsafe.
If your JSP is not threadsafe you will have to add the isThreadSafe="false" (note quotes) in order for things to work correctly. I'm probably a bit pedantic when I say that it does not make your JSP threadsafe but it does make your web application threadsafe by instructing the servlet container to cater for the thread-unsafety of your JSP.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is JSP thread safe?