如何实现单例用于应用服务器,单例可以吗?
我有一些经常运行的代码(对于每个网络服务请求)。
该代码是从应用程序服务器 (Websphere 7) 托管的 Web 服务中调用的。
我注意到 Websphere 使用了很多可能是单例对象的类(例如 BOXMLSerializer(用于反/序列化业务对象)或 BOFactory。
例如,我想节省为每个 Web 服务请求创建新对象的成本。
正在创建在应用程序服务器正常运行期间存在的单例是处理此问题的最佳方法吗?
Websphere 是否对此类事情提供任何帮助?
I have some code that gets run a lot (for every webservice request).
The code is called from within a web service which is hosted by an application server (Websphere 7).
I noticed Websphere uses a lot of classes that presumably are singleton objects (such as BOXMLSerializer (for de/serializing business objects) or BOFactory.
I want to save on the cost of creating a new object for every web service request for example.
Is creating a singleton that lives for the duration of the uptime of the app server is the best way of dealing with this?
Does Websphere provides any help with these sorts of things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
erloewe 是正确的,普通的单身人士可以工作。不过,关于 Singleton Session Bean —— 它是 J2EE6 规范的一部分,并且在 WAS7 中不可用(因为它只是 J2EE5)。不过它将成为 WAS8 的一部分。
erloewe is correct, an ordinary singleton could work. Regarding the Singleton Session Bean though -- it's part of the J2EE6 spec and is not available in WAS7 (since it is only J2EE5). It will be part of WAS8 though.
是的,你可以做一个普通的单身人士。然而,由于类加载器的工作方式,如果您有多个需要类似服务的应用程序,那么它可能与您的应用程序不完全相同。因此,您可能应该创建一个 单例会话 Bean。
Yes, you could make an ordinary singleton. However due the way the classloader works it might not be exactly same for your applications if you had several applications requiring similar service. For that reason you probably should create a Singleton Session Bean.