Servlet 3 spec and ThreadLocal

Posted by mindas on Stack Overflow See other posts from Stack Overflow or by mindas
Published on 2011-02-20T23:21:40Z Indexed on 2011/02/20 23:25 UTC
Read the original article Hit count: 226

As far as I know, Servlet 3 spec introduces asynchronous processing feature. Among other things, this will mean that the same thread can and will be reused for processing another, concurrent, HTTP request(s). This isn't revolutionary, at least for people who worked with NIO before.

Anyway, this leads to another important thing: no ThreadLocal variables as a temporary storage for the request data. Because if the same thread suddenly becomes the carrier thread to a different HTTP request, request-local data will be exposed to another request.

All of that is my pure speculation based on reading articles, I haven't got time to play with any Servlet 3 implementations (Tomcat 7, GlassFish 3.0.X, etc.).

So, the questions:

  • Am I correct to assume that ThreadLocal will cease to be a convenient hack to keep the request data?
  • Has anybody played with any of Servlet 3 implementations and tried using ThreadLocals to prove the above?
  • Apart from storing data inside HTTP Session, are there any other similar easy-to-reach hacks you could possibly advise?

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading