• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronise request object?

 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me rephrase my question:

"Is there under any circumstance/necessary to synchronize the request object?"
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since there is only one thread per request

there is no need of sinchronizing
 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic