2

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

Bukhtawar
  • 85
  • 10
  • possible duplicate of http://stackoverflow.com/questions/10096483/is-threadlocal-preferable-to-httpservletrequest-setattributekey-value – Adam Burley Dec 13 '16 at 12:02

1 Answers1

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