users@glassfish.java.net

Re: Findings for “Cannot allocate more connections” exception.

From: <glassfish_at_javadesktop.org>
Date: Wed, 16 Sep 2009 04:42:40 PDT

Ola,

Thank you for the clear description of your problem, and the simple example. This made it a lot easier to investigate.

The reason you're getting this error appears to be that you're creating a connection, using it and closing it 40 times in a single container-managed transaction. Even though you're closing the connection every time, the connection won't be returned to the pool until the transaction is committed, which happens when the feed() method returns. So when you call createConnection() for the 33rd time, there are no free connections available in the pool and you get that error.

You have three options

1. increase the pool size

2. change your session bean to use bean-managed transactions, and perform each call to feedOne() in a separate user transaction

3. change your session bean so that you don't create a new connection and session for every message. Instead, when feed() is called, create a new connection and session, use them to send all 40 messages, and then close them.

If possible, I would go for (3) because it is simplest, uses the least resources, and fastest. Note that by default it still sends all 40 messages in the same transaction.

If you need more information on how to do any of these, just ask.

Nigel

MQ team
[Message sent by forum member 'nigeldeakin' (nigel.deakin_at_sun.com)]

http://forums.java.net/jive/thread.jspa?messageID=364176