No best answer available. Please pick the good answer available or submit your answer.
May 24, 2006 17:20:53
Gurpreet Singh
RE: Why is the action class is singleton in nature? Is...
No it won't create a bottleneck as each request will be processed in separate thread. If would have created bottleneck it create separate instance for each request.
We just have to make sure that we are not using any instance variable in execute method.
RE: Why is the action class is singleton in nature? Is...
Because here action class acts as a front controller so each and every request should go through it and for logging mechanism its easier You need not write Log4j class again and again in each servlet.
RE: Why is the action class is singleton in nature? Isn't this creates a bottleneck for the requests?
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. Struts 2 Action objects are instantiated for each request so there are no thread-safety issues. (In practice servlet containers generate many throw-away objects per request and one more object does not impose a performance penalty or impact garbage collection.)