aspose file tools*
The moose likes Servlets and the fly likes How container handle this situation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How container handle this situation?" Watch "How container handle this situation?" New topic
Author

How container handle this situation?

Jigar Damani
Greenhorn

Joined: Jul 04, 2011
Posts: 8
We know that Servlet loads in to memory only once when first request comes for it and for all subsequent request, new threads create by container.
We also know that synchronized constructor is not possible.

Now my question is:

Assume simultaneously 100 requests come for same Servlet (assume requests come at same time from all client to server).
On first request, container will create object of class and then thread. So if 100 request comes simultaneosly, How it will synchronized object creation?
So how container handle this situation?
How container first load Servlet into memory and at that time prevent remaining 99 request to wait?

Hope I am clear with my question.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

First of all, I believe all production environment servlets are loaded at atartup. No one keeps waiting for the requests to come in for a "Login" servlet.

Having said that even if 100 requests come in without even a millisecond difference, I think its up to the specific container implementation what should happen in such a situation.


SCJP, SCWCD.
|Asking Good Questions|
Jigar Damani
Greenhorn

Joined: Jul 04, 2011
Posts: 8
No...All servlets are never loaded at startup unless set explicitly parameter in web.xml.
It always loads when first request come.

It is true that situation will be handled by Container but how that I want to know.
How container deal with situation? That logic I want to know.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

You'll need to find the source code from an open source container and examine it. The Servlet Spec does not dictate details to that level.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2402
    
  28

I am guessing here, but the container is probably synchronizing inside the Factory method.

This question is not really a "servlet" question. The core of the question is "In a concurrent environment, how is a lazy loaded singleton guaranteed to be a singleton?" You might want to look into Singleton pattern, and Factory Pattern. This page has a list of references that you can go through.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Jigar Damani wrote:No...All servlets are never loaded at startup unless set explicitly parameter in web.xml.

That is exactly my point.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How container handle this situation?