The ActiveMQ project site, 2004–2007 · independent archive
Independent historical archive. This site preserves the ActiveMQ project pages that were published at activemq.org in 2004–2007. It is not the project’s website and is not affiliated with or endorsed by the Apache Software Foundation. ActiveMQ and Apache are trademarks of the ASF. For current downloads and documentation go to activemq.apache.org.

Archive › Documentation › How do I use JMS efficiently

Archived page

How do I use JMS efficiently

Archived from http://www.activemq.org/site/how-do-i-use-jms-efficiently.html, captured 2006-08-24 · view the capture · Added by James Strachan, last edited by James Strachan on Mar 29, 2006

Reusing expensive objects

JMS is designed for high performance. In particular its design is such that you are meant to create a number of objects up front on the startup of your application and then resuse them throughout your application. e.g. its a good idea to create upfront and then reuse the following

  • Connection
  • Session
  • MessageProducer
  • MessageConsumer

The reason is that each create & destroy of the above objects typically requires an individual request & response with the JMS broker to ensure it worked. e.g. creating a connection, session, producer, then sending a message, then closing everything down again - could result in 7 request-responses with the server!

Note a little trick - you can reuse the same MessageProducer for sending messages to different destinations; just create it with a null destination and specify it on the send method.

Other performance tips

Also see

Client side versus Server side

Using pure JMS on the client side is fine. However in server side applications (such as services consuming requests from a queue), if you wish to consume messages fast and efficiently you should use JCA Java Connector Architecture.

JCA supports the pooling of JMS connections & sessions and MessageListeners, parallel message processing efficiently as well as thread pooling and transaction & exception handling. Also JCA will work with any JMS provider with a JCA Resource Adapter.

Typically JCA is used in a J2EE container via MDBs; though there is a POJO Spring based JCA Container you can use, which is simple and lightweight and easy to embed inside Tomcat or any J2SE application.

More from the archive