tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Q: SingleThreadModel and Tomcat
Date Wed, 11 Dec 2002 01:33:47 GMT


On Mon, 9 Dec 2002, David Boyer wrote:

> Date: Mon, 09 Dec 2002 12:19:12 -0600
> From: David Boyer <David@bvu.edu>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Q: SingleThreadModel and Tomcat
>
> It seems like different servlet containers vary in how they approach access to classes
that implement SingleThreadModel. When multiple threads want to access the class, some servlet
containers will create multiple instances of the class while others queue the threads for
exclusive access to a single instance of the class.
>
> Which approach does Tomcat take?
>

Until relatively recently, Tomcat did the latter approach. Current
versions support a pool of instances.

However, in general, I would recommend against usting SingleThreadModel in
your applications.  The sense of thread safety that you get is an illusion
if you're also using sessions - it's very easy to triger multiple requests
to the same session at the same time.  In addition, dealing with the pool
of STM servlet instances is just wasted overhead that slows your app down.

Far better would be to learn how to write thread-safe servlets in the
first place.  It's not that hard -- the principal thing to avoid is using
instance variables (in your servlets) to represent state information for a
particular request.

Craig



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


Mime
View raw message