Actionservlet is singleton class? what the reason behind it?
Actionservlet is singleton class? what the开发者_如何学Go reason behind it?
See this blog posting:
http://mohammedimrankhan.blogspot.com/2009/07/why-actionservlet-is-singleton-in.html
The short answer is that all servlets are required (by the Servlet specs) to be thread-safe and reentrant, and if a class is thread-safe and reentrant it may as well be implemented as a singleton.
J2EE specification mandates that every servlet needs to work in this way but some application servers are violating the specification by creating multiple objects for ActionServlet when more than 'n' requests are coming at a time,to see only one Object for ActionServlet at any point of time,it is made as SingleTon Class.
Not only Actionservlet but also all your Action classes are singleton.
As Per My knowledge Action Servlet class is not a singleton class. why because a class follows some rules like create private constructor, private static variable and override clone method,if a class create with above rules then that class is Singleton class.but if u see the source file of the actionServlet class there is no private constructor and no static variable , no override clone method.. So ActionServlet class is NOT SINGLETON CLASS... NOTE: If a class is Singleton class,then only we can create only one object.But created only one object class is not a singleton class.....even though ActionServlet class created only one object by web-container.but that class is not a Singleton class.that is Problem of Web-container .web-container happy with one object.
---Let me Known if my answer is correct or not..
--Thanks
精彩评论