On Sun, 12 Sep 1999, Anamitra wrote:
> Hi
> Can anyone suggest which one is better in terms of performance ---
> maintaining a pool of servlets using Single ThreadModel or just keep
> the servlet as it is ie only one instance. I understand that the
> answer depends on whether to make ur servlet thread safe or not. I
[ ... ]
Well, you *always* have to make your servlet thread-safe.
FWIW, my impression, mostly from past discussions on this list (you
might look them up), is that SingleThreadModel is a bad idea, for
performance reasons, and because it is not the panacea for thread
safety that it at first appears, and hence can mislead you into
thinking that your code is thread safe when it's not. The best thing
is to design your code/system so that contention issues are avoided as
much as possible, and when they might occur, synchronize the code on
the smallest block possible. I realize that is easier said then done.
Basically you need to worry about when more than one thread may try to
manipulate incompatibly some object, usually some shared resource.
That shared resource can be an instance or class variable (local
variables are safe), something in the session, an output
stream/writer, a file, a database (although some provide their own
synchronization), etc.
If you're going to have to deal with these kinds of issues a lot, it
might be good to invest in a book about it. The two books I have seen
most recommended are:
Java Threads by Oaks and Wong (this is an O'Reilly book)
Concurrency in Java by Doug Leas
I might not have the complete title right on that latter book.
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html