This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Servlet engine creates a separate thread for every request and assigns that thread to service() method in its multithreaded
servlet and finally it removes that thread after completion of service() method execution.
It happens for every request. Your servlet engine may create a new thread for every request by default. This default behavior reduces performance because creating and removing threads is expensive. This can be avoided by using the thread pool. Servlet engine creates pool of threads at start up and assigns a thread from pool to every request instead of creating a fresh thread every time and it returns that thread to the pool after completion. The size of the thread pool depends upon configuration parameters of the pool. The pool will have minimum and maximum number of threads and you can configure these numbers in the configuration file of your servlet engine. The number of maximum and minimum threads in pool depend upon concurrent users for your application. You have to estimate number of concurrent users for your application and give the thread pool size based on that. Obviously there is a limit on thread pool which depends on your hardware resources. By setting thread pool size correctly, The performance of servlet improves significantly. Your application server/ JSP engine may not have facility to configure thread pool. Tomcat's Servlet Engine has the facility to configure thread pool. Look at your application server / servlet engine documentation for information about thread pool.
The container is capable of creating threads in a pool and allocates them to each request. You cannot allocate a thread to a method. How each thread is assigned to the request is the container's responsibility.
is my question still clear to you or not. Please also read HeadFirst Jsp and Servlet Book
Your tone seems off.
Joined: Oct 04, 2006
i think question and answer is both clear to me..and what i was expecting not getting the answer !
You can close the issue.I am ok & will check it from myself.
So you were posting a question whose answer you already knew ?
If your question is still unanswered you can elaborate on it. That will attract more replies.
Joined: Oct 04, 2006
no its not like that .. my question was very clear that ..you know service() method is Multi-threaded in Nature in Servlet.
For that we have to create multiple threads to access the service() method in order to execute the code synchroization.
But i had douts , as i read in internet that maxThread arguments in Server.xml file used to create multiple thread in advance at startup.
I wanted to head my query in that way.. but other replyers are replying me in another way which is not my question. So i said i will try to find answer from myself once i get time.