Connection objects support concurrent use. The following code illustrates the implementation within the queue domain. Sessions The Session , QueueSession , and TopicSession interfaces represent a single threaded context for sending and receiving messages. A client uses them to create one or more MessageProducers or MessageConsumers . They also provide a factory for creating messages and define a serial order for the messages they consume or produce.
Sessions provide a natural way for clients to organize interactions with a provider.
The following code illustrates an implementation. Message producers The MessageProducer , QueueSender , and TopicPublisher interfaces represent objects that are used to send messages to a destination. The MessageConsumer , QueueReceiver , and TopicSubscriber interfaces represent objects that are used to receive messages sent to a destination. I've provided the complete source code for those readers who can't sleep until they see it all. For instructions on downloading, extracting, setting up, and running the code, please read the accompanying sidebar .