• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Safe

 
Sharma Anjali
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ques from j2eecertificate

Which of the following attribute scopes are thread-safe? [Check all correct answers]

Correct Answers given are:
1. Request attribute.
2. Response attribute.

Explanation given is
The request attribute and response attribute are thread-safe because the servlet container creates a single HttpServletRequest and a single HttpServletResponse per request. Therefore both attributes are only available for that request and hence cannot be shared by other requests.



What are response attributes?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Response attributes refers to Objects that can be stored in the HttpServletResponse while your application is processing the request/response. HttpServletResponse.setAttribute("something", new Object());
 
Francois Roland
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, the HttpServletResponse.setAttribute(String, Object) method doesn't exist. This method is only present on the ServletRequest interface. The reponse object represents what's being sent to the client. And the client browser cannot use any custom parameters.

Nevertheless, the HttpServletResponse interface allows you to specify cookies, status code and headers. And these one are considered thread-safe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic