Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SpringMVC works on Single Thread Model or Multithread Model?

I have confusion regarding Single Thread Model and Multithread Model. What type of model SpringMVC works on?

Thank you

like image 441
Oomph Fortuity Avatar asked Dec 07 '22 00:12

Oomph Fortuity


2 Answers

If you mean "does Spring MVC implement the javax.servlet.SingleThreadModel interface?" then it does not.

SingleThreadModel guarantees that "servlets handle only one request at a time." ( from the API docs ). This is generally managed by the servlet container which will maintain a pool of Servlet instances and allocate one to each incoming request. This is a rarely used model of execution, and the interface itself has been deprecated as of Java Servlet API 2.4, with no direct replacement.

With Spring MVC you should assume that your controller will be handling more than one request at a time, which makes it your responsibility to ensure that your processing is thread-safe.

like image 89
DaveH Avatar answered Mar 22 '23 22:03

DaveH


SpringMVC controllers are singletons, and serve concurrent requests. They are used in a multithreaded fashion, and so must be written to be threadsafe (no shared state between executions).

like image 35
GreyBeardedGeek Avatar answered Mar 22 '23 23:03

GreyBeardedGeek