简体   繁体   English

Actionservlet是单例类吗? 背后的原因是什么?

[英]Actionservlet is singleton class? what the reason behind it?

Actionservlet is singleton class? Actionservlet是单例类吗? what the reason behind it? 背后的原因是什么?

See this blog posting: 请参阅此博客文章:

http://mohammedimrankhan.blogspot.com/2009/07/why-actionservlet-is-singleton-in.html 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. 简短的答案是(根据Servlet规范) 要求所有Servlet都是线程安全的和可重入的,并且如果类是线程安全的且可重入的,则它也可以实现为单例。

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. J2EE规范要求每个Servlet必须以这种方式工作,但是某些应用服务器违反了该规范,即一次要发送多个“ n”个请求时,为ActionServlet创建多个对象,从而在任意时刻仅看到一个ActionServlet对象。时间,它作为SingleTon类。
Not only Actionservlet but also all your Action classes are singleton . 不仅Actionservlet,而且您所有的Action类都是单例的

As Per My knowledge Action Servlet class is not a singleton class. 据我所知,Action Servlet类不是单例类。 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. 为什么因为一个类遵循一些规则,例如创建私有构造函数,私有静态变量和重写克隆方法,所以如果一个类使用上述规则创建,则该类为Singleton类。但是如果您看到actionServlet类的源文件,则没有私有构造函数而且没有静态变量,没有重写clone方法。.因此,ActionServlet类不是SINGLETON CLASS ...注意:如果一个类是Singleton类,则只能创建一个对象。但是仅创建一个对象类不是Singleton类.....尽管ActionServlet类仅由web-container创建了一个对象。但是该类不是Singleton类。这就是Web-container .web-container对一个对象感到满意的问题。

---Let me Known if my answer is correct or not.. ---让我知道我的答案是否正确。

--Thanks - 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM