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?
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.
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”.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With