GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Struts
Go To First  |  Previous Question  |  Next Question 
 Struts  |  Question 42 of 103    Print  
Why is the action class is singleton in nature? Isn't this creates a bottleneck for the requests?

  
Total Answers and Comments: 3 Last Update: August 04, 2009     Asked by: Sharan 
  
 Sponsored Links

 
 Best Rated Answer

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.


 
Is this answer useful? Yes | No
May 19, 2007 11:07:07   
kiran19999        

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.

 
Is this answer useful? Yes | No
August 03, 2009 18:15:17   
geeksterrahul Member Since: July 2009   Contribution: 9    

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.)
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape