wood burning stoves*
The moose likes Servlets and the fly likes How Container creates the Threads for Service() method at Startup on Load ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How Container creates the Threads for Service() method at Startup on Load ?" Watch "How Container creates the Threads for Service() method at Startup on Load ?" New topic
Author

How Container creates the Threads for Service() method at Startup on Load ?

Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Prabhat Ranjan wrote:
But how server creates thread at stratup for Service() method of servlet ?


What does this mean.. ?

When the container reads the web.xml, and if it finds any servlet mappings with load-on-startup +ve values, it starts loading them.


- Chinna
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

But how server creates thread at stratup for Service() method of servlet ?


I do not understand your question. Threads are objects and are created for classes. service() is a method. Can you elaborate on your question ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Control Thread pool

Control Thread pool

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.

http://www.precisejava.com/javaperf/j2ee/Servlets.htm see this link and content from above.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
is my question still clear to you or not. Please also read HeadFirst Jsp and Servlet Book for the same where it has been mentioned about my query.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Content that you posted.. is very clearly telling.. what is thread pool in sevlet context.

Still your question is not clear !
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
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.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

i think question and answer is both clear to me


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.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Container creates the Threads for Service() method at Startup on Load ?