Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Thread model

Tags:

jsp

servlets

If a servlet implements Single thread model interference ,How servlet container ensure that servlets handle only one request at a time ? Even single thread model interface has no methods too.Thanks.

like image 808
Warrior Avatar asked Jan 31 '26 08:01

Warrior


2 Answers

The servlet container creates a pool of servlet instances, and keeps track of which instances are currently "in use". If all of the instances are "in use" when a new request comes in, the container could either wait for an existing one to become free, or create a new instance to handle the request.

The single thread model isn't widely used though - it's better to make the servlet itself stateless, and allow several requests to be handled simultaneously.

like image 149
Jon Skeet Avatar answered Feb 03 '26 09:02

Jon Skeet


The idea is not to rely on SingleThreadModel to take care of threading issue. As it is not mandated for servlet containers to bind to the singlethreadmodel contract, it is advisable not to rely on the container to instantiate multiple instances of servlets.

like image 20
user640554 Avatar answered Feb 03 '26 09:02

user640554



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!