Hi Jeff,

As I understand it, and to answer your question, what you propose is a bad
idea :o).  Unless your Servlet implements the SingleThreadModel, each
request (i.e. service(), doGet(), doPost() ) is automatically started on a
separate thread for you by the servlet engine.  What you want is already
done for you.  You need to make sure your servlet is thread safe. Briefly,
don't alter instance variables outside of the init() method.

I'll invite others on the list to please correct any errors in the above.

Check out the following books for all the details:

Inside Servlets by Dustin R. Callaway, Addison-Wesley ISBN 0-201-37963-5
Java Servlet Programming by Jason Hunter and William Crawford, O'Reilly ISBN
1-56592-391-X

Good luck,
Robin

-----Original Message-----
From: Jeff Borton [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 11, 1999 3:30 AM
To: [EMAIL PROTECTED]
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:


void doGet(HttpServletRequest req, HttpServletResponse resp)
{
        Runnable objectToHandleRequest = new
RunnableObjectToHandleRequest(req,
resp);
        Thread newThread = new Thread(objectToHandleRequest );
        newThread.start();
}

In this way I'm sure I have all my variables and objects within one thread
where I can control the accessing/changing data.  And I can have one
database connection per thread.

Is this a bad idea or a good idea?

Thanks,
Jeff

___________________________________________________________________________
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