----- Original Message -----
From: Jeff Borton <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 11, 1999 11:29 AM
Subject: manually multi-threading


> Ok,
>         I've search the archive looking to see if anyone has "talked"
about this
> before, but I didn't see any postings.  So I'm going to ask.  I'm
developing
> a servlet that I want to have multi-threading support in.  I thought if I
> made the servlet multi-threaded the servlet engine would create a new
> thread/instance for each person "hitting" my servlet. But from some of the
> other posts I've seen this isn't the case, unless I use the single
threaded
> model.  But from the same posts, it sounds like that is going to be a
> performance hit.  Question: will I get the same performance hit if I do
the
> threading myself?  Example:
>
>
Actually the way the threading is usually handled means that the cost of
servicing
1 servlet instance via N threads is a lot cheaper than servicing N instances
of the
servlet with N threads.

Normally threads would be pooled by the servlet engine so there is little
overhead
in threading the requests and you avoid the 1 process per request problems
associated
with cgi scripts.

The only time you need to worry about thread issues is when you have
instances of shared
resources that need to be made thread safe. Typical example of that would be
connections
to a database via a connection pool.

Remember that local variables inside the request methods are thread safe as
each invocation
of the method is unique to the thread that does the invocation.

For simple servlets like the HelloWorld servlets that come with almost every
servlet
engine install you needn't worry what is going on around you, you can just
treat the code
as if threads did not exist at all.

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

Reply via email to