Skip to main content

JMS Behavior Question

No replies
dmocek
Offline
Joined: 2004-06-30

I'm seeing a behavior in the JMS queue which was unexpected (at least for me). I understand why it's happening, but I'm looking for a way around it. My scenario (this is just an example to give an idea of what I want to do) is that I have a MDB which displays anything I send to it to a web browser. I have many other beans which send data to this queue to which the "Browser Display MDB" is a consumer. The JMS queue has 32 connections available. In one of my beans, which provides messages to the queue, I want to do something like this:

for (int i = 0; i < 1000000; i++) {
send data to the queue;
}

Currently (I'm using NetBeans 6.5), the code NB's puts in creates a connection for each message. After 16 messages are sent, things stop. The reason being that a connection is opened for each producer and consumer for each message sent, which totals 32 connections. After 16 messages are sent, there are no more connections available. Moreover (and this is what surprises me) the connections aren't closed until the thread returns, even though the connection.close() method is called. How do I get around this? I know I can create the connection, send the messages, then close the connection, but for reasons I won't go into here, this isn't what I want to do. I'd like to be able to open a connection, send a message, and close the connection, and do this for as many messages as I'd like within the current thread.

Thanks,
Darryl