Discussions

Hi guys,
How does the thread local works in web applications. Does each http request has a unique thread local reference ?? Let me elobarate my question a bit. I have a logger instance that i need instantiate depending on some conditions. So each time a http request hits my web server, I create a logger instance and put in the thread local, when i am done processing the request, in the filter before dispatching the request, i remove the thread local reference.
But my question is, Since the web server process the http requests depending on its own thread management. Is there any chance that two http requests getting the same thread local reference.
If i am not clear or have confused you, Please let me know i will detail the problem with some code.
Thanx and Regards
KR Kumar

Most of the webservers use 'thread per request pattern', that means each http request is assigned to a different thread always.
So there is no chance that two different HTTP request would end up using same getting the same ThreadLocal reference.
It might help though to provide information about which webserver you are using.
HTH

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.