Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 14029 invoked from network); 2 Feb 2000 21:02:09 -0000 Received: from unknown (HELO umpqua.dat.com) (209.241.199.17) by 63.211.145.10 with SMTP; 2 Feb 2000 21:02:09 -0000 Received: from mytownnet.com (dhcp109_10.dat.com [198.145.109.89]) by umpqua.dat.com (8.8.8+Sun/8.8.8) with ESMTP id NAA01034 for ; Wed, 2 Feb 2000 13:01:40 -0800 (PST) Message-ID: <38989B35.18A9DC50@mytownnet.com> Date: Wed, 02 Feb 2000 13:01:41 -0800 From: "Craig R. McClanahan" Organization: MyTown Network, Incorporated X-Mailer: Mozilla 4.61 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-dev@jakarta.apache.org Subject: Re: Running multiple servlet instances References: <36E6F54C1C95D211BE1200805F57F1E6033506BF@xcup-25005.mis.tandem.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit "Clark, Tom" wrote: > The mechanism would need to cache the instances and select among them when > each request is received. But they don't need to be run one at a time, > they can be run concurrently. Each instance is single threaded, but not the > class as a whole. The separate instances may run concurrently, but the call to the service() method in any single instance must be synchronized in order to conform to the servlet spec requirements reagarding SingleThreadModel. > > Does Tomcat currently queue up requests when a servlet is busy? Would > this also work for a pool of servlets? > Tomcat does not queue up requests by itself, but uses the feature of the "synchronized" key word to fake this. The code that actually calls your servlet method looks sort of like this: Servlet instance = ; if ((this is a SingleThredModel servlet>) { synchronized (instance) { instance.service(request, response); } } else { instance.service(request, response); } In other words, for STM servlets the calls are single-threaded because of the "synchronized" block. For non-STM servlets, the requests all run concurrently. In both cases, there is one and only one instance of the servlet, per definition in the "web.xml" file. If you implement a cache of instances, you will want to maintain your own queue of waiting requests. The issue is that you don't care *which* instance becomes ready next, so you don't want to queue requests for a particular instance the way that the "synchronized" block above does it. In essence, pretend your servlets are bank tellers, who can serve one customer at a time. What you want is a single input queue of waiting customers -- any one of which can be served by any available teller -- instead of a line per teller. If you've done multithreaded programming before, this is not hugely difficult, but it is definitely interesting. > > Tom > Craig