John Larson wrote:

> Hi,
>
> I have a question about DB connections.  My testing doesn't match what I
> read in a couple books, so I am confused...
>
> Background/Environment:
> I am using Oracle 8.0.4 and the Oracle thin driver.  My servlet is using
> the SingleThread implementation and I create a connection to the DB in
> the Init method of the servlet.  The servlet engine is JRun 2.3.
>
> Connection con; //Declared within the servlet class before the init
> method
>
> //In init
> String url = "jdbc:oracle:thin:@ip:port:dbname";
>        con = DriverManager.getConnection(url, "db","pw");
>
> After I run the servlet the first time, Oracle reports 7
> connections to my Servlet!  I only create one connection in the Init
> block.  My
> servlet does declare two different result sets and two prepared
> statements, all using the "con" connection object.  They are not
> explicitly closed.
>
> If I run the servlet several more times, there are still 7 connections,
> so it appears that they are being reused.
>
> Question:
> How did I get more than 1 connection to the DB?
>
> Thank you for your time and assistance,
> John

Servlet engines are free to create more than one instance of a servlet if they
want to.  In many of them, they create multiple instances of servlets that
declare themselves SingleThreadModel to help improve response time, since any
one instance is (in effect) synchronized  on its service() method.

For example, Apache JServ creates five instances of a single thread model
servlet.  This would create five connections to the database with your code
(once per instance).

Craig McClanahan

___________________________________________________________________________
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