2 Replies Latest reply on Jul 17, 2003 4:41 AM by kar2000

    Connection

    Amit Amit Newbie

      Hi,
      Generally to send or receive a message the steps we follow are
      (1) Get the JNDI initial context.
      (2) Look up a connection factory.
      (3) Obtain a connection from the factory.
      (4) Create a session tied to the connection.
      (5) Look up the destination (topic or queue).
      (6) Create a message producer or a message consumer (specific for the topic or the queue).

      I am bit confused at step number 1 to 3 . Do we have to repeat all these 3 steps again and again or we can use the same connection as long we want to use it . What are the issues with using same connection or diff connection each time user wants to send or receive message ?

      Any commnets ?????????

        • 1. Re: Connection
          Nathan W. Phelps Novice

          Per the JMS spec, Connections are heavy-weight objects, and thus you want to create as few as possible. The general strategy is to create only one Connection. So...
          1.) Get the JNDI InitialContext
          2.) Look up the ConnectionFactory
          3.) Obtain a Queue/TopicConnection from the ConnectionFactory
          4.) Use the Connection factory method to create a Session. The JMS spec states that Session are not heavy-weight objects, so the general strategy is to partition your workload across several Sessions.
          5.) Look up the destination
          etc...

          On an additional note, once you have looked up at ConnectionFactory or Destination there is no need to look it up again. Just hang on to the reference and keep using it.

          • 2. Re: Connection
            kar2000 Newbie

            Well, I have a doubt in this regard - is there any means of finding in the jboss server side and not in the database server side,

            how many connections are there in the pool,

            how many connections are in use and

            how many connections are being returned at a given point of time?