如何实现单例用于应用服务器,单例可以吗?

发布于 2024-10-06 01:06:43 字数 280 浏览 5 评论 0原文

我有一些经常运行的代码(对于每个网络服务请求)。

该代码是从应用程序服务器 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

濫情▎り 2024-10-13 01:06:43

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.

谁的年少不轻狂 2024-10-13 01:06:43

是的,你可以做一个普通的单身人士。然而,由于类加载器的工作方式,如果您有多个需要类似服务的应用程序,那么它可能与您的应用程序不完全相同。因此,您可能应该创建一个 单例会话 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文