tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lightbulb432 <>
Subject RE: Is ThreadLocal safe to use in servlets
Date Sun, 24 Jun 2007 17:18:40 GMT

To conserve resources when multiple <Connector> elements are configured.
> No point in having a multitude of idle threads when some <Connector>s
> are only lightly used or the usage pattern varies with time.

Is it safe to assume that this is the way to go, or are there ever, ever any
times when it would be less desirable to go this route than the default
thread-pool-per-connector element? (I ask in terms of performance or other
production characteristics, rather than the initial extra few minutes to
configure that element and figure out how to correctly use it...?)

Also, using this method can threads only be shared between Connectors
associated with a single Engine (because Executor is a child of Service, not
Server), rather than being shared between every request to all web
applications on this instance of Tomcat?

I have another question about using ThreadLocal as an instance variable in a
threadsafe Singleton. If the Singleton has 5 instance methods, each of which
requires use of the value stored in the ThreadLocal, I see one option:

- Start each method with a call to a private method that returns the value
in the ThreadLocal

void method1of5() {
  String myString = getStringFromThreadLocal();

Is there another alternative, which would reduce the duplication of that
first line for each of the five methods? One thing I thought of (though it's
not possible, but maybe you can suggest other alternatives) is to somehow
have an instance variable that stores the value of that call, that each
method could use directly?

String myString = getStringFromThreadLocal();

void method1of5() {

Of course this isn't possible the way I've shown, because the myString
instance variable is only initialized once, and shared between all users of
the Singleton. (Though it does simplify each of the 5 methods, making them
oblivious to the fact that they're dealing with ThreadLocals, and that's
what I'm hoping you might be able to suggest a way of doing...)
View this message in context:
Sent from the Tomcat - User mailing list archive at

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message