Interview Questions

Is it OK to add new sessions and subscribers to a Queue or Topic Connection once it has been started?

BEA WebLogic Questions and Answers


(Continued from previous question...)

Is it OK to add new sessions and subscribers to a Queue or Topic Connection once it has been started?

Yes, with one caveat. You may not add new subscribers/consumers to a session if it already has active async consumers. Sessions must only be accessed single-threaded as per the JMS spec. If you feel you need to do this, create a new Session and add it to that one instead.
You can add receivers to a started connection. A receiver in itself is not asynchronous. You need a listener to make it asynchronous. The first creation of a receiver is always safe. If you then add a listener for that first receiver, you have to worry for any future receivers in that same session. You can create new sessions and the first receiver for that session with no worries.
Once you want to create a second receiver in a session, if the first receiver has a MessageListener, you have to take care to make sure there are no other threads of execution in that session. You can do this by stopping the connection or actually creating your receiver from the onMessage routine of the first receiver.

(Continued on next question...)

Other Interview Questions