This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Multiple threads of a servlet instance and servletConfig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Multiple threads of a servlet instance and servletConfig" Watch "Multiple threads of a servlet instance and servletConfig" New topic
Author

Multiple threads of a servlet instance and servletConfig

ganga rk
Greenhorn

Joined: Jan 11, 2011
Posts: 5
Each servlet has a unique servletConfig.
Does multiple threads of a given servlet instance share the same servletConfig object ?
Please respond....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Don't know. Doesn't matter. Since one only reads from the ServletConfig, and never writes to it, there are no multi-threading issues.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
M Nadeem
Greenhorn

Joined: Feb 10, 2011
Posts: 1
Right answer. ServletConfig is read only object. All of its properties are set by JSP/Servlet container. Access of multipal threads have no harm to Servlet Config.
ganga rk
Greenhorn

Joined: Jan 11, 2011
Posts: 5
So when we have a situation like this:
" Many requests are coming in for a given sevlet A.
So the container would create threads of that servlet(A) for each request.
Now each of this thread would have a servlet config."

Now, would all the threads be having the same servlet config i.e will the container create only one servlet config for a servlet instance(for A in our case)and pass its copy to its threads?
Or will it create a servlet config for each of the thread?
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 512
Hi,
There is only one instance of the servlet and hence one instance of ServletConfig.
The threads that process the requests call the service() method of the Servlet which has one single instance.
The thread and the instance are two separate thing.
Hope this help you to clarify your understanding about the same.

Regards,
Amit
bala rimmalapudi
Greenhorn

Joined: Feb 11, 2011
Posts: 7
Yes, Every servlet will have only one ServletConfig, and the same ServletConfig will be used by multiple threads of that specific Servlet.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Point to be noted here is one servlet per jvm..


Regards
KumarRaja

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple threads of a servlet instance and servletConfig