HJW
HJW

Reputation: 23443

If Struts 1 action classes are singletons, does it mean there cannot be 2 threads of the class available?

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

Answers (2)

Rudy
Rudy

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

p27
p27

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

Related Questions