Daniel--

Realize that if you implement SingleThreadModel, the servlet engine is free
to instantiate any number of Servlet *instances* (as opposed to running
multiple Threads through a single instance) of your Servlet--that could
easily account for the multiple database connections. If I'm right, you have
the Connection as a member of the servlet, and when multiple instances were
constructed, multiple Connections were opened. When you dropped
SingleThreadModel, you went back to a single instance (but multiple
Threads).

For the most part, if you do as Ron suggests, below, you won't have too much
problem with handling multiple threads in your servlet. Try to stay away
from state members in your Servlet (have everything stored in the
HttpSession--that also makes your servlet distributable later), and you'll
be fine.

Ted Neward
Java Instructor, DevelopMentor ( http://www.develop.com )
http://www.javageeks.com/~tneward

-----Original Message-----
From: Ron Reynolds <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Wednesday, December 15, 1999 8:34 AM
Subject: Re: Problems Using JRun and JDBC with Single-Thread Model


>two rules of thumb i've run into with mutli-threaded servlets that uses
>database:
>1. don't use instance variables if you can help it (everything stack
>based) and,
>2. use a conneciton pool for your database connections (they're too
>expensive to make all the time and most drivers are limited in how many
>you can make).
>HTH.
>..............ron.
>Daniel Branch wrote:
>>
>> I have recently written my first servlet that connects to a database to
retrieve information which is then e-mailed to a number of different
addresses.
>> I ran it successfully on Servlet Runner and then transferred the program
to JRun.  I have noticed a problem where the servlet runs seven times,
although I am only running it once, hence creating seven connections to my
interbase database.
>> I have found that the problem comes from implementing the single-thread
model, in that the problem disappears when the single-thread model is not
implemented.
>> If anybody knows why this is - and can offer me any advice on what to do
next - I would greatly appreciate your help - either on how to correctly use
the single-thread model, or how to make my servlet thread-safe - it will
hopefully be accessed by a large number of people at any time!
>> I appreciate your time and thank you in advance
>>
>> Daniel Branch
>>
>>
___________________________________________________________________________
>> 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
>
>___________________________________________________________________________
>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

___________________________________________________________________________
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

Reply via email to