Pavan Singaraju wrote:

Hi,
   I have a basic question about servlets in Tomcat 5.0.18. In theory, when
there are simultaneous requests come for a servlet, it will either queue the
requests and serve one by one or create multiple threads of the servlet and
serve the request.
   My question is, what / how tomcat handles this situation?

As I understand it one instance of the servlet per webapp is accessed from all threads in a reentrant manner. This is why you normally can't use any class instance variables in a servlet. The only queueing that occurs is in the connector's thread pool when all threads are busy handling requests.

   I need the answer for this, because, i have a synchronized access to an
object from the servlet, and if tomcat handles the monitor for the object
then i don't need to handle the monitoring condition else i may have to do
it.
   I understand that Tomcat has a SingleThreadModel interface that allows
only one thread access/One request at a time model. But help me solve the
previous problem

SingleThreadModel has it's uses, but is also hard to get right and usually discouraged because of that. I'd say you are going to have to implement monitoring to prevent concurrent access where necessary. Just try to keep the sync blocks small so a minimum amount of time is spent there and only as necessary.

Your object is probably best served stored in the servlet context (ie application scope) with logic that handles synchronizing on update operations.


--David

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to