aspose file tools*
The moose likes Servlets and the fly likes How to handle simultaneous access of one servlet by 50 clients Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to handle simultaneous access of one servlet by 50 clients" Watch "How to handle simultaneous access of one servlet by 50 clients" New topic
Author

How to handle simultaneous access of one servlet by 50 clients

Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 97
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

Joined: Jul 31, 2008
Posts: 129
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.


SCJP 80% SCWCD 89%
Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 97
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

Joined: Mar 22, 2000
Posts: 12788
    
    5
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.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to handle simultaneous access of one servlet by 50 clients