"lieth78" wrote :
| Here is an summary of what is done in the code:
| 1- When the client is started:
| this.queue = (Queue)ctx.lookup("queue/myQueue");
| ConnectionFactory connFac =
(ConnectionFactory)ctx.lookup("ConnectionFactory");
| this.jmsQueueConnection = ((QueueConnectionFactory)connFac).createQueueConnection();
| this.jmsQueueSession = this.jmsQueueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
|
|
| 2- The client then loops and invokes the readMessages service, which content is
described here:
| this.jmsQueueConnection.start();
| QueueReceiver receiver = this.jmsQueueSession.createReceiver(this.queue);
| //In the second version I declared the receiver object as instance variable
| //instead of local variable: I instanciate it when the readMessages is //invoked for
the first time, then I just use the instance
| Message msg = receiver.receiveNoWait();
| //And then msg processing
|
| 3- When the client is stopped:
| jmsConnection.close();
|
| Did I make a mistake somewhere?
|
A couple of observations.
1) You are using the old JMS 1.0 API (QueueConnection and TopicConnection) it is better
practice to use the united Session/Connection objects from JMS 1.1- althought this is no
big deal.
2) Why are you creating your receiver in the loop?
This is poor practice. Not only will it be slow, it seems you are not closing them either
- so eventually you will run out of memory or some other resource (which is probably what
is happening in your case)
There are a lot of good resources on the web that describe how to use the JMS API.
The first thing I would do is to go through a JMS tutorial to get familiar with the basic
concepts.- the one on the
java.sun.com is fairly good.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3984093#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...