Themes created by Tomcat

I have a basic question about creating Tomcat threads. Is each browser instance running in a single thread, or does it spawn multiple threads to process one instance of the browser instance?

I take a link to the current thread in the code and call the activecount method, and it shows 20, which indicates 20 active threads. Therefore, I doubt where this value is configured from. Is there any option to set active threads to

while (iter.hasNext()) { GrammarSection agrammarSection= null; try { agrammarSection = (GrammarSection) iter.next(); } catch (Exception e) { System.out.println("DDD if it come in exception "+Thread.currentThread()); System.out.println("DDD if it come in exception "+Thread.activeCount()); //IT PRINTS 20 
+4
source share
4 answers

Tomcat creates a thread pool. Typically, a single HTTP request is served by a single thread.

+2
source

Tomcat (and most servlet containers) uses thread pools. That is, they pre-initialize a custom number of threads, and whenever a request arrives at the server, the thread is taken from the pool and assigned to process the request.

+1
source

Tomcat uses a thread pool, see this link for a brief overview of the configuration:

Default Behavior for Tomcat Connector

In response to the question, "Is each browser instance running in one thread?" the answer is "dependent":

One HTTP request that returns text, etc., will consume one acceptor stream.

However, if your displayed page includes images (on the same server instance), or if it uses frames, the browser will also make requests for them (because each image / page will require a different HTTP request to the server).

And ... the above refers to HTTP connector streams. Of course, you can have a servlet that is multithreaded (to perform some arbitrary task). This will not reckon with the "maxThreads" limit specified in the above configuration, but will display as active threads in the JVM.

+1
source

In general, this is really not the case.

The discussion here said that 1 HTTP request would be served by a single Tomcat thread. But you should not think that 1 page will trigger only 1 HTTP request.

At least it depends on which browser you use, how many resources on 1 page and whether there is AJAX, support live connections.

(1) A single browser instance spawns multiple threads on the browser / client side to load resources for one page and will occupy multiple threads in Tomcat / Apache / Weblogic / Websphere / regardless of the application you use. This is due to the nature of the modern multi-threaded browser. If you are really talking about a simple HTML page, it can spawn only one (working) stream in Tomcat, but when you add other resources on the page, such as images, images can (and most likely) will be loaded with the page browser usually does not wait until the entire page loads before loading the images. This can be understood when you use tools such as FireBug (in the Net section). Pages do not load sequentially.

(2) In an AJAX application, one page also invokes multiple threads on servers.

(3) Keep in mind that HTTP 1.1 (if you are not already using HTTP 1.0) will support the connection until the HTTP timeout. By default, this connection will not be closed. You need to look at the Keep-Alive parameter in the Tomcat / WAR configuration. You may need to add a reverse proxy (e.g. Apache, nginx, Squid, Varnish) before Tomcat to offload some of these supported connections.

+1
source

All Articles