aspose file tools*
The moose likes Servlets and the fly likes Is request and resonse objects are 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 request and resonse objects are thread safe?" Watch "Is request and resonse objects are thread safe?" New topic
Author

Is request and resonse objects are thread safe?

sureshreddy puli
Greenhorn

Joined: Sep 28, 2005
Posts: 29
Please tell me about the thread safe of request and response objects.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Generally the objects are thread safe, however stateful. So, one thread can initiate reading of data, and another thread trying to do the same can end up with meeting EOS.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Each request runs in a seperate thread, so the particular objects are thread safe. however, session and context attributes are NOT thread safe, so yuo have to be careful when you are working with them.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Request and Response objects are local to their own methods and not shared between servlet threads, thus they are by nature, thread safe. The only requirement from the servlet specification is that you should not keep references to them after the method ends, for example put them in class level members, put in session, etc; because the behavior of Request and Response after the method returned are undefined.


SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is request and resonse objects are thread safe?