aspose file tools*
The moose likes Servlets and the fly likes Creation of Servlet instances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creation of Servlet instances" Watch "Creation of Servlet instances" New topic
Author

Creation of Servlet instances

C Shinde
Ranch Hand

Joined: Oct 22, 2009
Posts: 60
I have a simple application that I create, using JSP/Servlet. The application consists of a single page, where a person enters some infomation and submits it, I need to show the submitted information another page.

I have 1000 users and all the users log on to the application at the same time.

Will the server load 1000 instances of the servlet for each user or will it have only 1 addressing all the users? I am a bit confused on this?
I need to decide which server I need to deploy this application to. Can I use tomcat to deploy this application to? Do I need to consider clustering for this simple application?

Now I could assume that this servlet is thread-safe. So multiple users can use the same instane of the servlet.

Regards,
CShinde


Regards,
Chetan Shinde
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Firstly - yes, there will be only one instance of your servlet catering to all 100 user requests. However, there will be 100 threads representing each of the requests. So you will have to be careful about shared data. To be on the safe side, avoid using or be extra careful about any data that you define as a member/class variable.

Secondly - Tomcat can handle a load of 100 concurrent users without any fuss. I don't think you really need to bother about clustering, or for that matter load-balancing for a user load like that. The upper limit of the user load is subject to the kind of data structures you're using, and the hardware capabilities of your setup.
C Shinde
Ranch Hand

Joined: Oct 22, 2009
Posts: 60
Well 100 users sounds fine, what about 1000 users, what is your views?

Also what will happen if my application is synchronized? How many instances will the container create for 1000 users? Will it be a unique instance for each user?
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Now, why would you think that making your application 'synchronized' will have anything to do with the number of servlet instances that get created? I'm sorry to break it to you, but synchronized or not, even then there will be ONLY one servlet instance for any number of user requests. Making your app synchronized will only help in keeping the threads [for every request] from interfering with each others data.

As for the number of users, you've got to realise that Tomcat as a server is capable of handling a really large number of parallel requests. I'm quite sure that the number is much >> 1000 concurrent requests. The exact number I am not sure of. However, if your application processes a really large amount of data for every request, then you can witness an awful response time even for 10 concurrent users.
C Shinde
Ranch Hand

Joined: Oct 22, 2009
Posts: 60
Sorry to go into Java basics but as far as I know there are 2 things when you talk about threads, a Servlet being Thread Safe, which means even if multiple users try to use same servlet there wont be any clashes for each of these users.
Now if I make my servlet implement SessionSyncronization it means that I am forcing a single user to use a Servlet at a time, in this case wont the 1000 users get a serial access to the 1 instance of the servlet? This will slow down the response, should the container not create multiple instance of the Servlet to cater to all these request then?

Please pardon me if I am worng but this is what I expected the Container to do.

OK I have read over a couple of forums and I accept that my understanding is wrong. I will read what tomcat does and get back to you.

Here are a few links that I can share with you too just FYI, which kind of proves me wrong!

http://www.jguru.com/faq/view.jsp?EID=1041533

BTW what is this tag load-on-startup in the web.xml mean?Does this mean that load so many instances of the servlet? I have normally seen most of the applications have this value as 1.

Thanks in advance.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

C Shinde wrote:BTW what is this tag load-on-startup in the web.xml mean?

A quick search of the Servlet Spec is best to answer questions like this. Or even a quicker Google-ing...

Hint: it has nothing to do with the number of servlets loaded.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
C Shinde
Ranch Hand

Joined: Oct 22, 2009
Posts: 60
Oh ok, the load-on-startup is the load order and has got nothing to do with the number of servlet instance.

So if I have 2 servlets declared in the web.xml as



The as NewServlet's load-on-startup is 1 and TestServlet's is 2. The container will first load NewServlet and then TestServlet.
Thanks all!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creation of Servlet instances