This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 41634
    
  55
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: 41634
    
  55
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.

 
 
subject: Confusion regarding the number of instances for concurrent servlet accessibility