4 Replies Latest reply on Jul 17, 2003 5:46 AM by kar2000

    JBOSS Forcing Database Connection to close() -- Is this Smar

    kchillar Newbie

      Hi, I have a concern regarding the connection to database in JBOSS.

      JBOSS is forcing me to close Database connection at the end of every method that uses a database connection.

      Will it not become very expensive or underneath, does it do a smart handling ?
      ( I mean it really does not close the connection but mark it for reusal and uses it next time !!)

      What I want is, get a database connection in ejbCreate() for a session bean and make all the methods in the bean use that connection ( ofcourse before a connecction is used, in each method I will make sure its not closed etc.).

      Currenlt JBOSS does not allow me to do this. Could it be some transaction setting in deployment descriptor that changes this behaviour ??


        • 1. Re: JBOSS Forcing Database Connection to close() -- Is this
          Jon Barnett Master

          I assume you are talking about stateless session beans. Although it is surprising that JBoss gives warnings about the resource use in your implementation, it is not unexpected. It is hinting that you are implementing a potential scalability problem.

          A pooled database connection is a scarce resource. We pool connections so that many EJBs in the container can share the connection. The idea is to use the connection for only as long as we need to send or receive data to the datasource, performing our work as quickly as possible. When we have finished with the connection, we return it to the pool so other EJBs can use the resource - when you close a connection obtained from a DataSource, it returns the connection to the pool rather than closing the physical connection to the database (or to whatever you are connecting).

          In your case, you allocate a datasource connection to the stateless session bean for the lifetime of that instance (which can be a very long time). A stateless session bean is like a pooled connection, the instance is continually recycled.

          Suppose you have an application load that requires a constant fifteen instances of a particular stateless session bean. This locks in fifteen database connections purely for the use of these bean instances. Even when the beans are idle (not doing any work), no other EJB in the container can use the connections because your fifteen beans never release the connection back to the pool.

          If you want a dedicated connection for the instance lifetime of your EJB, you may as well implement a direct connection to the database rather than using a pooled connection. But this is not the most efficient use of resources.

          • 2. Re: JBOSS Forcing Database Connection to close() -- Is this
            kchillar Newbie

            Thank you for your reply.

            I think you answered my question. I don't want dedicated connection kept open alive for the lifetime of my session bean.

            If a call to close( ) on a datasource connection results in that connection being returned to pool
            that is perfectly what I want
            ( I was just making sure that JBOSS does that )

            • 3. Re: JBOSS Forcing Database Connection to close() -- Is this
              Jon Barnett Master

              Yes. That is right. But I made a mistake in not emphasising that you should not allocate the connection at ejbCreate for a stateless session bean as this means you allocate the connection for a very long time if you don't close it before you leave a method.

              Only get the connection in the method of the stateless session bean and release it before you leave the method. It is also best practice to hold the connection for as short a time as possible within the method.

              See this thread: http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=

              • 4. Re: JBOSS Forcing Database Connection to close() -- Is this
                kar2000 Newbie

                Well, I have a doubt in this regard - is there any means of finding in the jboss 3.0.7 server side and not in the Oracle 8 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?