aspose file tools*
The moose likes Servlets and the fly likes Which among the servlet objects are synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Which among the servlet objects are synchronized" Watch "Which among the servlet objects are synchronized" New topic
Author

Which among the servlet objects are synchronized

Ananda Sen
Greenhorn

Joined: Dec 05, 2007
Posts: 8
Among the servlet objects, like request, response, session, ServletContext, ServletConfig etc. which are synchronized?
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Ananda Sen wrote:Among the servlet objects, like request, response, session, ServletContext, ServletConfig etc. which are synchronized?


i didn't understand your question. are you talking about the paramerters , variables etc currently held by these objects ???

avi sinha


SCJP 5.0 SCWCD 5.0
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Objects are not synchronized - code is. You can generally find information about what is and isn't synchronized (or what is or isn't thread-safe to do) in the javadocs of a class.

Note that web apps are not thread-safe unless you make them so in your code.


Ping & DNS - my free Android networking tools app
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

Ananda Sen wrote:Among the servlet objects, like request, response, session, ServletContext, ServletConfig etc. which are synchronized?


As stated above look at the api docs.

Here's an example on how to make ServletContext attributes thread safe. You must lock your ServletContext if you want to guarantee thread safety:


avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453


Thread safe attributes or variables :

1> local variables within the service methods
2> request attributes

3> request parameters
4> servlet or context init-params etc

actually everything which can't be changed in a program are thread safe . 3 and 4 are just examples which i have added as they are frequently asked in mock exams.



avi sinha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which among the servlet objects are synchronized