You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Greg Ward <gw...@python.net> on 2004/06/07 21:20:22 UTC

Thread reuse question (Tomcat 4.1)

I have a question motivated by our application's slightly peculiar
logging requirements.  (Details below, if you're curious.)

Specifically, does Tomcat 4.1 reuse request-processing threads across
web apps, or only within a single web app?  I.e. if thread X is created
to service a request for web app #1, will that thread ever be used to
service requests for any other web app?  Or is it exclusively devoted to
the use of web app #1?

Rationale: we'd like our web apps to have per-user log files; this is
for a moderate-traffic, high-log-output family of applications, so
separating the log output by user makes sense.  The obvious way to do
that is have a thread-local log object that is initialized when starting
a request, and closed when finishing the request.

The catch: what state do I leave the ThreadLocal in when finishing each
request?  Right now, I'm pointing it to the default log file for the
current web app, eg. app1.log.  But if the thread that just processed a
request for web app #1 is reused for web app #2, and web app #2 does not
set the thread-local log object correctly, things will get confusing --
some libraries used by web app #2 in processing the request will log to
the thread-local log object, namely app1.log.

So at the very least, I'd like to know how Tomcat 4.1 reuses threads.
Better yet, I'd like to know if the servlet spec makes any guarantees in
this are -- I've read what I think are the relevant sections (2.2, 2.3),
but I didn't see anything.

Thanks --

        Greg

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