0 Replies Latest reply on Apr 22, 2002 4:53 PM by Cathy Zhang

    Is it a good idea to create multiple Connection objects?

    Cathy Zhang Newbie

      I have a question on the heuristic of setting up TopicConnectionFactory (or QueueConnectionFactory), TopicConnection and Topics (or Queues) in a bean that is designed to send messages to multiple topics that can be located either on a local machine or a remote machine. In terms of easy usage of this message sender bean, I would like to have this bean deployed once, then client of this message sender bean can do something like:
      messageSenderBean.sendMessage(aTopicJndi, aMessage).
      In my implementation, TopicConnectionFactory objects and TopicConnections are created during the creation process of this bean.

      My concern is that: Suppose I have 100 remote topics running on 100 remote JMS providers, then it means 100 topic connection factories and 100 topicConnections are created even I have only ONE such message sender bean active. and the number could be multiplied when multiple message sender beans are instantiated by the EJB container. According to JMS API doc, it says that Connection is heavy object,

      Here is an extraction of Connection interaface Java doc:

      Because the creation of a connection involves setting up authentication and communication, a connection is a relatively heavyweight object. Most clients will do all their messaging with a single connection. Other more advanced applications may use several connections. The JMS API does not architect a reason for using multiple connections; however, there may be operational reasons for doing so.

      Are ConnectionFactory and Topic heavy objects too? Will I be better off by delaying creation of TopicConnection
      object in the sendMessage()? or simply forcing only one ConnectionFactory/Connection/Destination in one message
      sender bean and deploying multiple message sender beans when I need to send messages to multiple topics?

      Thank you very much for your help!
      Cathy