This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle simultaneous access of one servlet by 50 clients

 
Sriram Sharma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is a very basic question and I would be very happy if somebody can help me get an understanding on this.

Let me suppose that there is only one servlet in my application.
Now, If there are 50 clients trying to access my application simultaneously, how to go about it?
How wil the servlet handle it? Can the servlet handle it automatically?
Or is there any configuration that we need to do?
Or should we make the necessary changes in the code itself?

There is only one servlet instance and how it can handle all the 50 calls?
Please help me out on this.

Regards,
Sriram
 
Praveen Sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet handles that automatically. That is what servlet is for. Each new request spawns a new Servlet thread on the server just to handle the new request. However, you might have to do some synchronization logic in the servlet so that there is no concurrency issues on data.
 
Sriram Sharma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that information Praveena.
But, when a servlet handles one request, how can it handle other simultaneous requests?
What is the basic involved here?
Is the handling of simultaneous requests servlet specific or container specific?

Regards,
Sriram
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The handling of simultaneous requests is built in to the servlet API.

Each request is assigned a Thread by the container - each request Thread gets a reference to objects implementi g ServletRequest and ServletResponse interfaces. These objects are hidden from all other "simultaneous" requests.

This is always hard for programmers moving from applications where there is only one Thread that interacts with a user to grasp.

You should look for a tutorial on servlet life-cycle.

Bill
(check out the ranch servlets faq page.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic