Why is the action class is singleton in nature? Isn't this creates a bottleneck for the requests?

Showing Answers 1 - 7 of 7 Answers

Gurpreet Singh

  • May 24th, 2006
 

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.

kiran19999

  • May 19th, 2007
 

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.

  Was this answer useful?  Yes

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.)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions