Oomph Fortuity
Oomph Fortuity

Reputation: 6178

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

Upvotes: 4

Views: 4777

Answers (2)

DaveH
DaveH

Reputation: 7335

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.

Upvotes: 8

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

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).

Upvotes: 7

Related Questions