aspose file tools*
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
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: 74

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: 39548
    
  27
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 - updated with new look and Ping home screen widget
Shivom Shukla
Ranch Hand

Joined: Jul 05, 2012
Posts: 74

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: 39548
    
  27
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: 74

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
Problem with instance variable in servlet
Session
How servlet is acessed
weblogic returns same session
Security in MVC Pattern