title: How to create custom object pools in Java application server
body: <p>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.</p>
  
  <p>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:</p>
  
  <ul>
  <li>How do I define/instantiate the pool?</li>
  <li>How do I access the pool? JNDI?</li>
  <li>What management capabilities are provided by the app server?</li>
  </ul>
  
  <p>I know how to implement an object pool in general. My question is mostly about creating a pool in a J2EE app server.</p>
  
  <p>I'm planning on using Glassfish, but I"m flexible if JBoss or something else will make this easier.</p>
  
  <p>Thanks!</p>