I need to have a request specific object and use that same object across the web application to get/set values to it to perform business logic for a particular request. Can I use request.setAttribute/request.getAttribute or should I use ThreadLocal. My understanding is every request is handled by a separate thread from the thread pool. I have this in a Spring Web Application.I can also see a RequestContextHolder ,not sure which would be the right fit
Asked
Active
Viewed 1,202 times
2
-
possible duplicate of http://stackoverflow.com/questions/10096483/is-threadlocal-preferable-to-httpservletrequest-setattributekey-value – Adam Burley Dec 13 '16 at 12:02
1 Answers
1
It appears that you want an application wide attribute to be available to each specific request. For this you can use request.getServletContext().setAttribute() and request.getServeltContext().getAttribute(). The ServletContext represents the application so attributes set with it are available for the lifetime of the application and can be used by multiple requests.

mmulholl
- 281
- 2
- 7
-
-
please clarify the question, you said "....and use that same object across the web application to get/set values......" . – mmulholl Jan 14 '16 at 12:06
-
I meant one object for the entire execution of one request thread (request specific object) across different web components – Bukhtawar Jan 14 '16 at 19:13