wood burning stoves 2.0*
The moose likes Servlets and the fly likes Synchronise request object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Synchronise request object?" Watch "Synchronise request object?" New topic
Author

Synchronise request object?

Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
In Head First Servlet and JSP, they have mentioned session and context attributes are not thread safe and only the request attributes are thread safe. So we don't need to synchronize the request object like synchronize the session and context object.
If so, my doubt is why request object is synchronised in <jsp:useBean.. scope="request"> page no:348 - chapter - 8 in HFSJ
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
Let me rephrase my question:

"Is there under any circumstance/necessary to synchronize the request object?"
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Mike Thomson:
"Is there under any circumstance/necessary to synchronize the request object?"


there is only one thread per request. so request is thread-safe.why you want to synchronize again? if you want then do in this way



but it looks bad
Pavan BH
Greenhorn

Joined: Sep 21, 2008
Posts: 7
Since there is only one thread per request

there is no need of sinchronizing
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
Seetharaman,

I know request attributes are thread safe and no need to synchronize as we are doing for context and session.

But in the Head first Servlets and JSP book,
for <jsp:useBean.. scope="request">, the generated servlet code in _jspService() method, they have synchronized the request object like below:
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Unless and until you are creating any Threads manually in your servlet file which access the request , there is no need to synchronize the request.


If you want something you never had do something which you had never done
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Synchronise request object?