Reputation: 23443
if Struts 1 action classes are singleton pattern classes, does it mean that there cannot be two threads of the class available for use?
My question came as a curiosity that if i were to mark a method inside of a Struts 1 class synchronized, does that mean that at any point that method may service only 1 thread.
private synchronized void runSubmitCalculatorState(ControllerRequest request,ControllerResponse response){}
Upvotes: 0
Views: 1831
Reputation: 7044
Singleton means only one instance of that class will be created through the whole application. It does not mean that there cannot be two threads of the class available for use.
Syncronized method means only one thread able to access that method at one time.
There is no direct relationship between syncronized and singleton, which means you can create either singleton or non singleton class to be syncronized.
Upvotes: 2
Reputation: 2222
Struts 1 Actions are singletons therefore they must be thread-safe because only one instance of a class handles all the requests for that Action. The singleton strategy restricts to Struts 1 Actions and requires extra care to make the action resources thread safe or synchronized while developing an application.
Upvotes: 1