如何在 Java 应用程序服务器中创建自定义对象池
假设我在 Java 应用程序服务器中有一个消息驱动 Bean (MDB)。 MDB 从 JMS 队列接收消息并将其传递给消息处理器。就我而言,消息处理器是一个非常重的对象,需要大量初始化,因此我不想创建一个新的对象来处理每条消息。相反,我想提前创建一个消息处理器池并使用它们来处理消息。
所以,我的问题是:在 J2EE 应用程序服务器中构建此池的“正确”方法是什么?是否有服务器内置支持定义自定义(非连接)对象池?在将池塞进单例中并希望获得最好的结果之前,我想利用对此模式的任何内置支持。特别是:
- 如何定义/实例化池?
- 我如何进入泳池? JNDI?
- 应用服务器提供哪些管理功能?
我知道一般如何实现对象池。我的问题主要是关于在 J2EE 应用程序服务器中创建池。
我计划使用 Glassfish,但如果 JBoss 或其他东西能让这变得更容易,我会很灵活。
谢谢!
Suppose I have a message driven bean (MDB) in a Java application server. The MDB receives a message from a JMS queue and passes it to a message processor. In my case, a message processor is an extremely heavy weight object that requires extensive initialization so I don't want to create a new one to handle each message. Instead I would like to create a pool of message processors ahead of time and use them to handle messages.
So, my question is: what is the 'correct' way to build this pool in a J2EE app server? Do any servers have built-in support for defining custom (non-connection) object pools? I would like to leverage whatever built-in support there is for this pattern before I just cram the pool into a singleton and hope for the best. In particular:
- How do I define/instantiate the pool?
- How do I access the pool? JNDI?
- What management capabilities are provided by the app server?
I know how to implement an object pool in general. My question is mostly about creating a pool in a J2EE app server.
I'm planning on using Glassfish, but I"m flexible if JBoss or something else will make this easier.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数应用程序服务器通常将 EJB 本身作为池对象进行管理。
实现应用程序最明显的方法是使用 MDB 本身作为消息处理器,然后使用应用程序服务器部署配置来配置池,这当然特定于您实际使用的服务器。
EJBs themselves are usually managed as pooled objects by most application servers.
The most obvious way to implement your application is to use the MDB itself as the message processor, and then configure the pooling using the application server deployment configuration, which of course is specific to the server you are actually using.
您可以尝试 Apache Commons Pool,它是一种用于池化应用程序对象的通用机制。
You could try Apache Commons Pool, it's a generalised mechanism for pooling application objects.
Java 5 附带了 Executor API< /a> 可以做到这一点。
Java 5 comes with the Executor API that can do this.