You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by du...@bankone.com on 2003/09/25 19:17:28 UTC

Using ThreadLocal with Tomcat4118 or greater

Hi,
I'm developing a servlet framework and have run into a design snag because
I don't know enough about how Tomcat handles threads. Long story short, I
want a quick way for any class running in the framework to get access to
the current request and response objects. I am tired of passing references
to these objects from class to class.

Another developer told me that I can use Threadlocal to create a
singleton-like class that is unique to each request because every request
runs in its own thread(big assumption that I am not too sure about). By
taking this approach I can then quickly import my thread local class and
have access to the request and response objects for the current request.

Before I decide to implement this does anyone know if I would run into any
snags on a high traffic site. Is it a guarantee that every request uses its
own thread? I understand threads get pooled but as long as I initialize the
threadlocal class on every request that would guarantee that each request
is getting the right request and response objects.

Can anyone see any instances when this would not work?

Thanks, - dkrebs




This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org