1

I'm having the problem that the maximum pool size of a SingleThreadModel servlet is on Tomcat 5.5 limited to 20 instances. I do not know where to configure it in Tomcat 5.5.

My HTTP connector is declared as follows:

<Connector port="8090" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="100"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />

Do you know where I could configure this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Fernando Rybka
  • 238
  • 1
  • 4
  • 14
  • Please tell us more: how do you know you're hitting such limit? an error message somewhere? How do you know tomcat is creating 20 instances? Do you mean handling 20 connections? – Simone Gianni Jul 27 '11 at 21:09
  • There's a difference between the number of *servlet instances* and the number of *connections*. Normally, a servlet container does not create one instance of a servlet for every connection. – Jesper Jul 27 '11 at 21:09
  • 1
    There's somewhere a major misunderstanding going on. There's usually only **one** instance of a mapped servlet during the entire application's lifetime. Perhaps your servlet implements the (since 2003 deprecated) `SingleThreadModel` interface? (which on Tomcat indeed has a default limit of 20 instances). If this is true, just get rid of that deprecated interface and rewrite your servlet so that it's threadsafe. Related: http://stackoverflow.com/questions/3106452/java-servlet-instantiation-and-session-variables/3106909#3106909 – BalusC Jul 27 '11 at 21:10
  • Hi all, i'm using SingleThreadModel and unfortunatly cannot get rid of it... it's an old app and that's how it's implemented... all of it. The problem was detected with a stress test tool. I myself am using JMeter to simulate calls to my app. As some of our servlets take about 5 minutes (and could be more then 20) to respond, it is easy to see that only 20 are been atended (debugging it from a filter or something like). If I alternate between 2 servlets, I can get 40 users "active" at the same time. – Fernando Rybka Jul 27 '11 at 21:16
  • P.S. The other requests are queued – Fernando Rybka Jul 27 '11 at 21:17
  • Okay, I have updated your question to clarify the one and other so that the common misunderstanding is removed. – BalusC Jul 27 '11 at 21:26

1 Answers1

4

This is as far as I see not configureable by XML.

It's however programmatically configureable by StandardWrapper#setMaxInstances(). You could do this in the init() method of your servlet implementing SingleThreadModel. I tested it here on Tomcat 7 and it works fine.

@Override
public void init() throws ServletException {
    try {
        Field wrappedConfig = StandardWrapperFacade.class.getDeclaredField("config");
        wrappedConfig.setAccessible(true);
        StandardWrapper standardWrapper = (StandardWrapper) wrappedConfig.get(getServletConfig());
        standardWrapper.setMaxInstances(100);
    } catch (Exception e) {
        throw new ServletException("Failed to increment max instances", e);
    }
}

This would in theory only not work on a Tomcat instance which is outside your control and might have some restrictive access policy on the particular classes.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi, i'm sorry to bother again, but i just know nothing about it... how can i load StandardWrapper inside my servlet once this class is inside catalina.jar above server libraries? – Fernando Rybka Jul 28 '11 at 17:34
  • I'd like to know the best way to do it, what ive done is to add to `common.loader` in catalina.properties the `${catalina.home}/server/lib/*.jar` – Fernando Rybka Jul 28 '11 at 18:49
  • Just add it to the compile time classpath. You don't need to add it to the runtime classpath, it's already there :) If you were using an IDE like Eclipse, just referencing Tomcat 5.5 as target runtime in project's properties would have been sufficient. – BalusC Jul 29 '11 at 00:00
  • Hi Balus, firs of all, thank you very much for your help! It worked perfectly! Didn't realize that the problem was with the singlethreadmodel and so I got stucked. Second, the specification of tomcat 5.5 says that Catalina folder is TOTALLY invisible to web applications, and so it is indeed. Maybe this model changes for tomcat 7. Furthermore, changing the catalina.properties works, not sure it is the best way to do it, but works! Thank you for your help! – Fernando Rybka Jul 29 '11 at 13:04