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.
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%
Joined: Apr 12, 2006
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?
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.