Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

isThreadSafe Doubt

 
Surajsingh Thakur
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we create a thread safe JSP ?

A <%@ page isThreadSafe = "true" %>
B <%@ page implements="SingleThreadModel" %>
C <%@ page isThreadSafe="false" %>
D <%@ page extends="SingleThreadModel" %>

Asnswer = c...
please explain why not a...thank you..
 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct answer is a only.

a tells that my servlet is thread safe and dont want to implement SingleThreadModel.

If you want to implement SingleThreadModel , go for
isThreadSafe="false" which will degrade the performance.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page isThreadSafe="true" %>
This implies that the JSP page author would take the full responsibility of making the JSP thread safe, which means the author would have necessary synchronized blocks. The container will not provide any help [help = make jsp implement SingleThreadModel marker interface].

When i write <%@ page isThreadSafe="false" %> means i don't know how to make the JSP thread safe and i leave everything to the container. Now when container translates the JSP to servlet, it makes the servlet to implement the SingleThreadModel with this every client request will have their own instances of the servlet hence making the JSP thread safe.

Hope this clears.
 
Surajsingh Thakur
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all...

 
arulk pillai
Author
Ranch Hand
Posts: 3385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet 2.4 specification deprecates
SingleThreadModel, which is the most common
mechanism for JSP containers to implement isThreadSafe.
Page authors are advised against using isThreadSafe, as
the generated Servlet may contain deprecated code.
- Sun Forums
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen Kumar:
a tells that my servlet is thread safe and dont want to implement SingleThreadModel.



Not really. In fact you are the responsible to make thread safe JSP.

<%@page isThreadSafe="true" %> means jsp allows concurrent access(multiple thread)

Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic