> Hello Friends,
Hi Nitin,
> I wrote a servlet which extended HttpServlet and implemented
> SingleThreadModel
>
> In the init method of this servlet I put a display statement just to
> find out how many times it gets called i.e how many instances of this
> servlet would get created.
>
> Then I invoked this servlet thru an HTML page. The display statement was
> shown 6 times which means that the server created 6 diff. instances of
> the same servlet. Am I right? How was this figure of 6 reached at?
>
Depends on your servlet engine but it is common practice to set up a pool of
SingleThreadModel
servlets. The number of instances is dependent on your servlet engine, check
your documentation
for details about this.
> How is this pool of instances used by the server? I then invoked the
> servlet more than 6 times and then expected the server to create some
> more instances to satisfy the additional requests however this did not
> happen. The server seamed to reuse the existing pool because it seems
> that the servlet after having sent back the response becomes free to
> handle new requests.Is this right?. The server then searches thru the
> existing pool to find out if any servlet instance is free to handle to
> new request or not.
You answered the question yourself Nitin, that is basically what happens.
> Also in this scenario the database connection got established 6 times.
> Is there any way to establish the database connection only once but
> still use SingleThreadModel
Would this be at all wise Nitin. If your DB server is not capable of
handling web traffic
demands then perhaps you should look at chaning to one that can.
In a test I ran I had a connection pool of 10 000 connections to a Sybase
Server 11
and then blasted the servlet with a stress tester to see if I could break
something
using actual SQL statements and stored procedures. The only thing that got
tired
of the process was me waiting for smoke to appear from one of the machines
because it
never happened.
6 Database connections is not many, don't worry too much about them. Not
only that but
I wouldn't really want to share 1 connection across several servlets because
of the problems
with transactions that may hit you.
Hope this helps
Andy Bailey
___________________________________________________________________________
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