Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Confusion regarding the number of instances for concurrent servlet accessibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Confusion regarding the number of instances for concurrent servlet accessibility" Watch "Confusion regarding the number of instances for concurrent servlet accessibility" New topic
Author

Confusion regarding the number of instances for concurrent servlet accessibility

Shivom Shukla
Ranch Hand

Joined: Jul 05, 2012
Posts: 77

Hi,

I am having this confusion, that if 5 clients (different web browsers or machines) are accessing one servlet at the same time, how many instances will be created of that servlet?
I know that servlet works on generating threads for processing the request from a particular web browser.

P.S. I know this is the incorrect forum to ask this but will this same thing happen in struts 2.0 action class in this same scenerio?

Thanks,
Shivom Shukla
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
One instance of the class will be created, which will be used for all concurrent threads. That's why it is important to write servlets in a thread-safe manner.

Struts 2 action class objects are created for each request, so they need not be tread-safe. Note that this is different from Struts 1.


Ping & DNS - my free Android networking tools app
Shivom Shukla
Ranch Hand

Joined: Jul 05, 2012
Posts: 77

Hi Ulf,

One instance is created if there are multiple requests from same client but,
will there be One instance created even if there are requests from different clients(web browsers) ?

So in struts 2.0, will there be different instances of the action class if more than one client try to access it?

Thanks,
Shivom
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
It has nothing to do with where the requests come from - there is no difference between requests coming from the same client, and requests coming from different clients, as far as the server is concerned.
Shivom Shukla
Ranch Hand

Joined: Jul 05, 2012
Posts: 77

Thank You for clearing my doubt Ulf.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion regarding the number of instances for concurrent servlet accessibility
 
Similar Threads
Security in MVC Pattern
Session
Problem with instance variable in servlet
How servlet is acessed
weblogic returns same session