Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If there are 100 simultaneous doGet() requests to a servlet, will it block other 99 requests until the called doGet() returns?

I read that the web server instantiates servlet once and then calls its doGet() and doPost() methods for each requests to this servlet.Now if there are 100 simultaneous requests to this servlet and the web server has called doGet() for one such request, will it block other 99 requests until the called doGet() method returns?

like image 788
vishesh Avatar asked Oct 21 '12 10:10

vishesh


People also ask

How can servlet handle multiple requests simultaneously?

A servlet is a singleton, and is shared among all the requests. Each request is served by a thread, and concurrent requests are thus served by concurrent threads, each calling the same servlet concurrently.

How many requests can a servlet handle?

c) Servlet container creates 4 sets of request, response objects on one set per each request. (if any change is occur recompile, reload.) Every thread can be identified through its “thread name”. Every object can be identified with its unique number called “Hashcode”.

How do you handle multiple requests at the same time in Java?

Your best option is to use ExecuterService which is kind of managed thread pool where you can specify thread pool size and submit multiple Runnable or Callable objects for processing.

Can we override doGet method in servlet?

Since the routing takes place in service(), there is no need to generally override service() in an HTTP servlet. Instead, override doGet(), doPost(), and so on, depending on the expected request type. The automatic routing in an HTTP servlet is based simply on a call to request.


2 Answers

No, it won't, it would just call doGet() on the same servlet instance in 100 different threads. The incoming requests would be blocked if there are no idle threads to process the requests.

like image 123
Vikdor Avatar answered Nov 15 '22 03:11

Vikdor


No, in the normal case new Thread is created for each request.

You can set the number of threads for each in your servlet container.

You can also set the thread to be blocking.

like image 39
px1mp Avatar answered Nov 15 '22 04:11

px1mp