What is the purpose of a JMS session? Why isn't a connection alone sufficient to exchange JMS messages between senders and receivers?
+4
A:
A Session object is a single-threaded context for producing and consuming messages. Although it may allocate provider resources outside the Java virtual machine (JVM), it is considered a lightweight JMS object.
A session serves several purposes:
- It is a factory for its message producers and consumers.
- It supplies provider-optimized message factories.
- It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.
- It defines a serial order for the messages it consumes and the messages it produces.
- It retains messages it consumes until they have been acknowledged.
- It serializes execution of message listeners registered with its message consumers.
A session can create and service multiple message producers and consumers.
One typical use is to have a thread block on a synchronous MessageConsumer until a message arrives. The thread may then use one or more of the Session's MessageProducers.
bobmcn
2010-04-21 20:59:24
The threading is a key point. Session on down (producers, consumers, messages) are not thread-safe. For this stuff, you must either protect from concurrent access or create multiple so multiple threads don't share.
John M
2010-04-22 17:20:02