threading issues with tomcat

2001-03-06 Thread Byrom Robert-LRB005

hello all

Im hoping someone can help, 

can someone please explain how the threading works when a new servlet is initialised 
within the tomcat container? If multiple requests are recieved for a servlet, is the 
same servlet data area shared amongst each thread that invokes the servlet? and if 
many requests are made for the same servet, how does tomcat deal with the demand? 

I need to know the stress that tomcat can handle.

if anyone can help this would be appreciated, 
thanks in advance.

rob


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




RE: threading issues with tomcat

2001-03-06 Thread Byrom Robert-LRB005

thanks for the help,

one further question, if I initialise a Database connection within  the init() method 
of a servlet and use this reference in the doGet() for example, will each servlet 
share this connection object? ie if more than one servlet requests the same connection 
would this result in a runtime exception?

ie

public void ExampleServlet extends HttpServlet{
private connection_;

public void init(){
//do something to open and get a database connection
}

public void doGet(HttpServletRequest req_, HttpServletResponse res_){
//now use the connection_ reference here to execute
//a database sql query
//if this reference is shared between multiple 
//servlet invocations is it right to assume this would
//be unsafe !
}
}

thanks again in advance!

robbie



-Original Message-
From: William Brogden [mailto:[EMAIL PROTECTED]]
Sent: 06 March 2001 14:01
To: [EMAIL PROTECTED]
Subject: Re: threading issues with tomcat




Byrom Robert-LRB005 wrote:
 
 hello all
 
 Im hoping someone can help,
 
 can someone please explain how the threading works when a new servlet is initialised 
within the tomcat container? If multiple requests are recieved for a servlet, is the 
same servlet data area shared amongst each thread that invokes the servlet? and if 
many requests are made for the same servet, how does tomcat deal with the demand?

 Only a single servlet object exists in the container but there
can be many Threads executing in the code. Each Thread has
a request object and response object (and possibly a session
object) belonging to a particular request. Each Thread shares
the instance variables of the servlet but local variables in
servlet methods are unique to the Thread.

 Thats why you should not use servlet instance variables for
anything unique to a particular request. Data that has to be
associated with a particular user between requests should be
stored in the session. 

-- 
WBB - [EMAIL PROTECTED]
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




Re: threading issues with tomcat

2001-03-06 Thread William Brogden



Byrom Robert-LRB005 wrote:
 
 thanks for the help,
 
 one further question, if I initialise a Database connection within  the init() 
method of a servlet and use this reference in the doGet() for example, will each 
servlet share this connection object? ie if more than one servlet requests the same 
connection would this result in a runtime exception?
 

Resources such as DB connections have to be specially managed
servlets to ensure that only one Thread is using a connection
at one time. Look for recent discussions of connection pools
in this mailing list.  

-- 
WBB - [EMAIL PROTECTED]
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




RE: threading issues with tomcat

2001-03-06 Thread Randy Layman


Actually that's not quite right.  Special resources (i.e. those that
shouldn't/can't be used concurrently by multiple threads) need to be managed
to control their usage.  Generally a Singleton is used to control access
(either by giving out multiple copies, like Database connections, or by
preventing the requesting thread from executing, like File I/O).

While using a Servlet is a generally accepted way of doing this, its
not the only way, or necessariy the best way depending upon your
application.

Randy

-Original Message-
From: William Brogden [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 06, 2001 9:52 AM
To: [EMAIL PROTECTED]
Subject: Re: threading issues with tomcat




Byrom Robert-LRB005 wrote:
 
 thanks for the help,
 
 one further question, if I initialise a Database connection within  the
init() method of a servlet and use this reference in the doGet() for
example, will each servlet share this connection object? ie if more than one
servlet requests the same connection would this result in a runtime
exception?
 

Resources such as DB connections have to be specially managed
servlets to ensure that only one Thread is using a connection
at one time. Look for recent discussions of connection pools
in this mailing list.  

-- 
WBB - [EMAIL PROTECTED]
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]