Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

is servlet/jsp thread safe?  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

is servlet/jsp thread safe?
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO.

Thanks
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But No.
It depends how you are doing it.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general Servlet/JSP are not thread safe.

Following are the guidelines:

1. Application (ServletContext) attributes, session(HttpSession) attributes, Servlet Instance variables and Servlet class variables are "not" thread safe.

2. Local variables (variables defined in a servlet methods) and request (ServletRequest) attributes are thread safe.

3. If you implement SingleThreadModel interface in a servlet then you can make Servlet Instance variables also thread safe. (In a JSP you implement SingleThreadModel by specifying page directive <%@ page isThreadSafe="false" %>

Note: SingleThreadModel interface is deprecated in Servlet API 2.4.

Alankar Yannam
 
Naresh Saw
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all


but if somebody ask u how u make ur servlet/jsp thred safe, not explicitly asking u context, session, request attibute, what will be ur answer.

again the page directive <%@page isThreadSafe="true"%> which is by default say that jsp is thread safe.

again confusing thing.

any clarifiction abt it.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the default is true. But, that is assuming that you will take care of actually making it thread-safe. The most appropriate thing to do is synchronize on any process/logic that will make your servlets (including servlets resulting from JSP) NOT thread-safe. (i.e. any logic that can be accessed by more than one thread simultaneously)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!