1

I am working on an enterprise application which is deployed to JBoss 4.2.3. It is using Servlet 2.5 specs.

The application has some JSPs which are using SingleThreadModel (STM) with this directive: <%@ page isThreadSafe="false" %>

I want to know how JBoss 4.2.3 implements SingleThreadModel (STM):

  1. Does it has only 1 instance of a servlet and serialize all requests on it?
  2. Or it has multiple instances of a servlet and process each request concurrently?

How can I find this information?

Thanks

srh
  • 1,661
  • 4
  • 30
  • 57

1 Answers1

0

As per JBOSS Documents, this can be done in both models:

The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet

And note that this is not completely thread safe:

Note that SingleThreadModel does not solve all thread safety issues

AND:

session attributes and static variables can still be accessed by multiple requests on multiple threads at the same time

So i think the answer is this directive (and also extending SingleThreadModel servlets) will prevent multiple threads to call service method of a single instance of your servlet at the same time and will not prevent web server from serving simultaneous requests with multiple instances of the servlet.

In other words, One single instance will not serve requests in multiple threads at the same time, but web server can create multiple instances of the servlet and assign each request to one instance at the same time.

UPDATE

I found a constant of 20 maxInstances in catalina core that will instantiate up to 20 servlet instances to serve simultaneous requests received to a servlet, if there are no free instances,otherwise wait to have a free servlet instance.

Shirin Safaeian
  • 950
  • 6
  • 18
  • The JBoss Documents link you gave is really just the original documentation of STM which you can also read at https://docs.oracle.com/javaee/7/api/javax/servlet/SingleThreadModel.html. This only talks about the 2 ways of implementing STM: single instance or multiple instances. It leaves it up to the vendors to use whichever strategy they like. I want to know what strategy JBoss 4.2.3 uses to implement STM. Thats the purpose of this thread. – srh Apr 23 '16 at 20:15
  • sorry for misunderstanding, i will update my answer if found anything – Shirin Safaeian Apr 23 '16 at 20:23
  • Does jboss use catalina as it's core engine? if this is true, there is a constant of 20 **maxInstances** in catalina core that will indicate when multiple requests received to a servlet, if it's busy, create new instance to reach 20 instances, and then wait to have a free instance. https://searchcode.com/codesearch/view/23011575/ – Shirin Safaeian Apr 23 '16 at 20:51