Dave Ray
Dave Ray

Reputation: 40005

How to create custom object pools in Java application server

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:

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!

Upvotes: 4

Views: 2499

Answers (3)

Massimiliano Fliri
Massimiliano Fliri

Reputation: 853

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.

Upvotes: 4

Aaron Digulla
Aaron Digulla

Reputation: 328624

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

Upvotes: 0

skaffman
skaffman

Reputation: 403501

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

Upvotes: 1

Related Questions