I was thinking that attribute in request or response is thread safe ..but i read in the specs that they are not so when setting an attribute in request object we have to synchronize that code...I was thinking the only way request object is not thread safe is if we store its reference and use it later on ..But one another question how its possible to use the request reference after the servlet life cycle is over...For reference pls go on page 28 SRV 18.104.22.168.3 in Servlet specs
SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
I think the request object is thread safe. The problem is about the attributes set in the request scope. The Attributes Objects are reference to the other objects with some attribute name , so there may be some other links to that object which can modify the object when the any service method is running.
Every time your browser sends an HTTP request the Web container will create a new request and response object. Those objects and their attribute-sets of objects will stay alive until the service method is done. Then the container will set those objects to be garbage-collected.
Only the session, context attributes are preserved so other servlets can reuse them
Joined: Mar 04, 2006
So, Request-scoped attributes are thread-safe, right? Thank you.
Joined: Jul 12, 2004
can anyone read page 28 SRV 22.214.171.124.3 in Servlet specs and answer the question with reference to it ..It clearly says that request object is not thread safe on that page in Servlet specs 2.4