When you talk about a Spring app being multithreaded, are you necessarily referring to whether the servlets that are defined in that app are multithreaded?
Or can a Spring app be configured to be multithreaded even if the servlets in the app are not multithreaded?
Single-threaded servlets are no longer supported. They have been deprecated for a long time, so all servlets are multithreaded.
Then, spring does not use servlets (apart from one - the dispatcher). It uses beans, which can be controllers, services and repositories (daos).
These beans are thread-safe (what I suppose you mean by "multithreaded") if they don't hold any data in their fields (apart from their dependencies)
In short - don't store any data in your spring beans. Pass all required data as parameters.
typical java web applications are multi-threaded in that every request is handled on its own thread. In such applications, you have to be careful when you have objects that maintain state (via modifying a static property, for example), as they can overwrite each other.
When you are talking about servlets, if two requests come in at the same time to the same servlet, the relevant servlet code is being executed twice concurrently. In frameworks like Struts or Spring, which delegate requests to objects, either the same bean instance can be reused, or a new bean instance could be created for each request, depending on how you have your framework configured (i.e. to use prototypes or singletons in the case of Spring)
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