Is it a good idea to use ThreadLocal as a context for data in web application?
That's what it was made for. But take care to remove the ThreadLocal on the end of the context, else you might run in memory leaks, or at least hold unused data for too long.
ThreadLocals are also very fast, you can think of it as a HashMap<Thread,Object>
, which is always queried with Thread.getCurrentThread()
.