wood burning stoves 2.0*
The moose likes Servlets and the fly likes Is my servlet threadsafe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is my servlet threadsafe?" Watch "Is my servlet threadsafe?" New topic

Is my servlet threadsafe?


Joined: Mar 15, 2004
Posts: 2
I'm trying to build a very simple MVC framework. I work with a single frontservlet, that dispatches the queries to handler objects. The handler are simple java beans, and the front servlet invoke them with the help of java.lanf.reflect. My problem follows:
I would like to know if it is possible to use the HttpServletRequest, or the HttpServletResponse, or the ServletContext, as object attributes for the handler?
I know that if my handler were servlets, I wouldn't be allowed to do that, because it's not threadSafe. But my handler are simple java bean that are invocated by the frontservlet with the reflect package.
Is my servlet threadsafe?
Any help would be nice.
Thank you, regards,

Tod Checker

Joined: Feb 19, 2004
Posts: 27
Its thread safe if the methods that use httpservletresponse, httpservletrequest, and servletcontext are declared and instaniated within a service method of the servlet. Anything outside the service methods are not thread safe.

Joined: Mar 15, 2004
Posts: 2
Thanks for your answer.
As my handler objects (who have the HttpServletRequest,HttpServletResponse,ServletCOntext) are dynamically (with java.lang.reflect) invokated in the service method and are never used outside service method, I know now that my FrontServlet is ThreadSafe.
jQuery in Action, 2nd edition
subject: Is my servlet threadsafe?
Similar Threads
synchronization of the connection object
Urgent !!! Scalabilty of Front Servlet
Instance variables in Servlet
Changing the url in browser