RE: Servlet Concurrency Issues

2005-06-08 Thread Michael Pasko
Thanks Chuck, that was exactly the problem.  I was under the very poor
assumption that a new thread and newly instantiated servlet object was
created every time a request was made, instead of all threads working on
only one instance of an object.  To mimic the desired behavior I've fixed
the problem by adding this (implements SingleThreadModel)...

public class ServletName implements SingleThreadModel

Now it would seem that if several 100 people were to access a servlet that
every time the following code was hit by a new thread:

PrintWriter out = response.getWriter();

It would direct all output (using out.println()) from all threads to the
most recent person to access the servlet.  

Follow up question:  With this in mind, what is the most common method of
writing thread safe code?  

Thank you very much for your help.

-Mike

-Original Message-
From: Caldarale, Charles R [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 07, 2005 1:15 PM
To: Tomcat Users List
Subject: RE: Servlet Concurrency Issues

 From: Michael Pasko [mailto:[EMAIL PROTECTED] 
 Subject: Servlet Concurrency Issues
 
 I started allowing other users on it, I stumbled on some problems.
 Basically what happens, when user A submits the form, and then 2 
 seconds later user B submits the same form.  User A stops getting 
 results, and User B receives the output for his request as well as
 the end of User A's request.

Probably not a configuration problem but rather implementation errors in
your servlet or some related object (such as the DB connection).
There's normally only one copy of the servlet object, and it will be
used concurrently by multiple threads.  Make sure you're not storing
request-specific information in there.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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

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



Servlet Concurrency Issues

2005-06-07 Thread Michael Pasko
I've recently developed a servlet that connects to an AS/400, and returns
results off an sql query based off criteria submitted by a form.  I've had
pretty much exclusive use of the Tomcat server during development, but when
I started allowing other users on it, I stumbled on some problems.
Basically what happens, when user A submits the form, and then 2 seconds
later user B submits the same form.  User A stops getting results, and User
B receives the output for his request as well as the end of User A's
request.  User A is on a different computer than B and both have different
session ID's.  I'm sure this is a configuration error on my part, but would
appreciate a direction on where to look.
 
PS - I create a session if it doesn't exist, and store the username and DB
connection in it.  (Will use JNDI later) 
 
 
 
 
I'm using Tomcat 5.5.7