• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it necessary to synchronize HttpServletRequest object  RSS feed

 
Arunabh Dash
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it necessary to synchronize HttpServletRequest object .
Please justify your answer .

With Regards
Arunabh Dash
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronize it, when?
What are you trying to do?

Generally, no.
Each request lives in it's own thread.
 
Arunabh Dash
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply . Actually a got a question like that in a test . I understand that each request lives in it's own thread .But i wonder is there any situation where i have to synchronize the request object else it will be hazardous ???

Thankx
Arunabh
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my best of knowledge request object is thread safe.Whenever the container gets a request it creates a request object and a new thread is created for processing the request.So I think that this request object is thread safe and you do not need to syncronize that.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arunabh Dash:
Thank you for your reply . Actually a got a question like that in a test .
Thankx
Arunabh


Is this a test that you've already finished or is this a current homework assignment?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need an extremely compelling reason to synchronize anything in a Servlet. Allow the web container to thread and synchronize your Servlet. Any sychronization should be left for JavaBeans or other business components.

-Cameron McKenzie
 
Arunabh Dash
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply . And yes , test was over 2 days back .
Then can i say that HttpRequest object is always thread safe !!!
Regards
Arunabh
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!