• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Creation of Servlet instances

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
C Shinde
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic