Reputation: 21893
I have a Struts 1/Spring 2 application. I am wondering is my Action
classes are Singletons shared by all session or if each user/session gets a new object of the Action
class?
Upvotes: 1
Views: 617
Reputation: 49402
I am not sure that Struts Action class is implemented as a singleton,but I can say that the framework just uses one instance of it and only one instance is used to process all incoming requests, care must be taken not to do something with in the Action class that is not thread safe. From the javadoc:
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
EDIT :
This is what the official Apache Struts page says :
Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be thread-safe or synchronized.
Upvotes: 2