File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Tomcat and threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat and threads" Watch "Tomcat and threads" New topic

Tomcat and threads

Panda Mima

Joined: Aug 04, 2006
Posts: 14
Do I understand it right that Tomcat is launching all filters, then servlets and even JSPs in the same thread? Of course it can launch other thread and it will handle other filters and servlets, but is there are any logic how it launches it's own new thread? Or can I force somehow to launch EACH filter, EACH servlet, EACH jsp in a new thread of Tomcat?

The problem is that some servlets I use they are thread sensitive, and I've noticed that calling in these servlets return the same value - http-8080-Processor25, which explains to me that all of them are working inside the same Tomcat thread.

But can I force somehow to launch everything in a new thread??

And what are the guarantee that if Filter will be launched in the Tomcat thread, that Servlets which are in chain with the Filter will be in the same thread???

[ August 17, 2006: Message edited by: Panda Mima ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Moved to the Tomcat forum.

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You want to re-work Tomcat because your servlets are not thread-safe?

Have you looked into any other options (synchronization, SingleThreadModel, making them thread-safe?).

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Do I understand it right that Tomcat is launching all filters, then servlets and even JSPs in the same thread?

That is a really odd statement!!! I suspect you are trying to create difficulties where none exist. The mental picture of how a servlet container works is quite a change from the picture of a desktop application.

In all servlet engines, Tomcat included, the container assigns a Thread to each request so if a request involves a filter, a servlet and a jsp, the same Thread handles them all. When the response has been finished, the container continues to manage the Thread, probably in some sort of pool, where it is available for the next request.

For example, my Tomcat server is set up for a maximum of 150 Threads but starts with a pool of 25 which is normally sufficient for the typical request load.

I agree. Here's the link:
subject: Tomcat and threads
It's not a secret anymore!