So according to this question Spring Controllers are singletons and there is one per webapplication. It does not make sense to me - if there are multiple users connecting to same Controller and one of them starts some long running task, it would mean that others would be blocked until Controller is unlocked. I must be missing something. Thx.
Asked
Active
Viewed 949 times
1 Answers
3
Spring Controller
s are singleton-scoped beans meaning only one can exist per Spring Application Context. So it's not by-nature singleton like say some Singleton-Design-Pattern-developed-class but by-virtue and guarantee of the Spring framework.
What you are describing sounds like a a hypothetical synchronization occurring on the Controller
's methods allowing only one request to go through at a time which is not happening because your Controller
methods will most certainly not be synchronized
.
Therefore things that can slow down your request will be things like the web container's max request threads (if I remember correctly in Tomcat by default it's 100) or Network delay or Resource consumption delay (i.e. DB).

dimitrisli
- 20,895
- 12
- 59
- 63
-
Thx for the clarification. Somehow I got the idea that if object is used by multiple threads, access to it has to be somehow controlled. But it makes sense that it does not count for stateless objects. – Petr Beneš Nov 24 '16 at 14:44