4

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!

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I'll give this a try. I wonder about how much control I'll get. For example, if there is a period of inactivity, will the AS empty the pool of MDBs necessitating another long initialization process the next time a message comes in?
This is really AS specific. My main experience is with JBoss and Weblogic, which both allow to customize passivation and disposal policies as well as pool size and behaviour. I think GlassFish is not different, and you can find relevant documentation here: docs.sun.com/app/docs/doc/820-7695/beaiu?a=view
The link is broken
1

You could try Apache Commons Pool, it's a generalised mechanism for pooling application objects.

Comments

0

Java 5 comes with the Executor API that can do this.

2 Comments

I'm not sure how this solves my problem, especially in the context of a J2EE app server.
You just have to synchronize the start/stop of your application in the app server with the executor and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.