Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 61084 invoked from network); 8 Dec 2000 19:50:33 -0000 Received: from lukla.sun.com (192.18.98.31) by locus.apache.org with SMTP; 8 Dec 2000 19:50:33 -0000 Received: from centralmail1.Central.Sun.COM ([129.147.62.10]) by lukla.Sun.COM (8.9.3+Sun/8.9.3) with ESMTP id MAA13807 for ; Fri, 8 Dec 2000 12:50:28 -0700 (MST) Received: from esun1as-mm. (esun1as-mm.Central.Sun.COM [129.147.34.144]) by centralmail1.Central.Sun.COM (8.9.3+Sun/8.9.3/ENSMAIL,v1.7) with SMTP id MAA21116 for ; Fri, 8 Dec 2000 12:50:28 -0700 (MST) Received: from eng.sun.com by esun1as-mm. (SMI-8.6/SMI-SVR4) id NAA21348; Fri, 8 Dec 2000 13:04:01 -0700 Message-ID: <3A313BDF.743030E2@eng.sun.com> Date: Fri, 08 Dec 2000 11:51:59 -0800 From: "Craig R. McClanahan" X-Mailer: Mozilla 4.76 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Re: limit threads per servlet in Tomcat References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N J Y wrote: > Hi > > I wish to setup Tomcat to limit threads per servlet, say 20 threads to > execute in one servlet concurrently. the 21th request would cause the > Tomecat engine to generate a new servlet instance. > There is no way to do this in Tomcat. On the other hand, doing this would not help performance at all ... it would actually make performance slightly worse (because of the additional memory occupancy of the second instance). It's also against the servlet spec to do this. > > Is there a way to do it. any comment appriciated. > > Also, what's the performance concerns. is that possible to create a pool of > servelts? > The standard mechanism for this is to say that your servlet implements the SingleThreadModel interface. This tells the servlet container to ensure that only one request at a time in any one servlet instance -- essentially the call to the service() method becomes synchronized. To keep performance from totally suffering when you do this, the servlet container has the *option* to create a pool of instances for you -- which means that the maximum number of requests you can process simultaneously is limited to the configured maximum number if instances in this pool. Tomcat does *not* support this capability -- effectively the pool size is one. Further, IMHO, using SingleThreadModel is a very bad idea. People like it because it lets them use instance variables to store per-request state information, instead of using local variables and passing arguments around (like they should :-). However, SingleThreadModel only gives you the illusion of thread safety -- you're still going to have to deal with simultaneous requests if you are using static variables, or if you are using sessions. Why artificially cripple your servlet's performance, and get yourself in trouble? You are far better off *not* implementing SingleThreadModel. Then, the only limit on how many simultaneous requests you can support is the maximum number of threads in your container, with no artificial limits imposed at the individual servlet level. > > Thanks > > Jay Craig McClanahan