5 Replies Latest reply on Oct 30, 2003 6:15 PM by Adrian Brock

    can't create a new connection

    kynix Newbie

      I have configured a datasource in jboss, and set the max-pool-size to 5000, then I start 100 threads, each invokes a finder method on a BMP. But it can be seen in the console that when the number of connection exceeds 60, no more connections could be created.
      This is my finder method:
      PreparedStatement pstmt = null;
      Connection conn = null;
      Vector v = new Vector();

      try {
      System.out.println("ejbFindByOwnerName(" + name + ") called");

      /*
      * Acquire DB connection
      */
      conn = getConnection();

      /*
      * Find the primary keys in the DB
      */
      pstmt = conn.prepareStatement("select id from accounts where ownerName = ?");
      pstmt.setString(1, name);
      ResultSet rs = pstmt.executeQuery();

      /*
      * Insert every primary key found into a vector
      */
      while (rs.next()) {
      String id = rs.getString("id");
      v.addElement(new AccountPK(id));
      }

      /*
      * Return the vector of primary keys
      */
      return v;
      }
      catch (Exception e) {
      throw new FinderException(e.toString());
      }
      finally {
      /*
      * Release DB Connection for other beans
      */
      try { if (pstmt != null) pstmt.close(); }
      catch (Exception e) {}
      try { if (conn != null) conn.close(); }
      catch (Exception e) {}
      }

      getConnection() is a method to get a connection from the datasource:
      try {
      Context ctx = new InitialContext();
      javax.sql.DataSource ds = (javax.sql.DataSource)
      ctx.lookup("ejbDataSource");
      return ds.getConnection();
      }
      catch (Exception e) {
      System.err.println("Could not locate datasource! Reason:");
      e.printStackTrace();
      throw e;
      }

      I use MS SQLServer2000 and JBoss3.2.2RC4. Who can tell me why? thanks in advance.

        • 1. Re: can't create a new connection
          Adrian Brock Master

          Post the error message.
          Is your db configured to allow more than 60 connections?

          Regards,
          Adrian

          • 2. Re: can't create a new connection
            kynix Newbie

            I have configured the SQL Server2000's connection constraints to no limits. The error message is:

            09:28:29,546 ERROR [STDERR] org.jboss.util.NestedSQLException: Could not create
            connection; - nested throwable: (java.sql.SQLException: [Microsoft][SQLServer 20
            00 Driver for JDBC]Error establishing socket.); - nested throwable: (org.jboss.r
            esource.JBossResourceException: Could not create connection; - nested throwable:
            (java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establ
            ishing socket.))
            09:28:29,546 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSo
            urce.getConnection(WrapperDataSource.java:106)
            09:28:29,546 ERROR [STDERR] at rtvu.enroll.prtvu.sessionejb.ProvinceschoolEn
            rollManagerBean.getConnection(ProvinceschoolEnrollManagerBean.java:584)
            09:28:29,546 ERROR [STDERR] at rtvu.enroll.prtvu.sessionejb.ProvinceschoolEn
            rollManagerBean.QueryExamByBmh(ProvinceschoolEnrollManagerBean.java:709)
            09:28:29,546 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor49.invoke(
            Unknown Source)
            09:28:29,546 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
            ke(DelegatingMethodAccessorImpl.java:25)
            09:28:29,546 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
            24)
            09:28:29,546 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$Conta
            inerInterceptor.invoke(StatelessSessionContainer.java:683)
            09:28:29,546 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
            nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
            09:28:29,546 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanc
            eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
            09:28:29,546 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
            nvokeNext(AbstractTxInterceptor.java:84)
            09:28:29,546 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
            hTransactions(TxInterceptorCMT.java:267)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
            (TxInterceptorCMT.java:128)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
            oke(SecurityInterceptor.java:118)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
            ogInterceptor.java:191)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
            ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
            nalInvoke(StatelessSessionContainer.java:331)
            09:28:29,593 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
            :700)
            09:28:29,593 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor45.invoke(
            Unknown Source)
            09:28:29,593 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
            ke(DelegatingMethodAccessorImpl.java:25)
            09:28:29,593 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
            24)
            09:28:29,593 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
            her.invoke(ReflectedMBeanDispatcher.java:284)
            09:28:29,593 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
            eanServerImpl.java:546)
            09:28:29,593 ERROR [STDERR] at org.jboss.invocation.jrmp.server.JRMPInvoker.
            invoke(JRMPInvoker.java:362)
            09:28:29,593 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor44.invoke(
            Unknown Source)
            09:28:29,593 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
            ke(DelegatingMethodAccessorImpl.java:25)
            09:28:29,593 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
            24)
            09:28:29,593 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(Unic
            astServerRef.java:261)
            09:28:29,593 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.j
            ava:148)
            09:28:29,593 ERROR [STDERR] at java.security.AccessController.doPrivileged(N
            ative Method)
            09:28:29,593 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Trans
            port.java:144)
            09:28:29,593 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMess
            ages(TCPTransport.java:460)
            09:28:29,593 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$Connection
            Handler.run(TCPTransport.java:701)
            09:28:29,593 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)
            09:28:29,593 ERROR [STDERR] Caused by: org.jboss.resource.JBossResourceException
            : Could not create connection; - nested throwable: (java.sql.SQLException: [Micr
            osoft][SQLServer 2000 Driver for JDBC]Error establishing socket.)
            09:28:29,593 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.local.LocalMa
            nagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.jav
            a:153)
            09:28:29,593 ERROR [STDERR] at org.jboss.resource.connectionmanager.Internal
            ManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPoo
            l.java:372)
            09:28:29,593 ERROR [STDERR] at org.jboss.resource.connectionmanager.Internal
            ManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:185)
            09:28:29,593 ERROR [STDERR] at org.jboss.resource.connectionmanager.JBossMan
            agedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:459)
            09:28:29,609 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
            ectionManager2.getManagedConnection(BaseConnectionManager2.java:417)
            09:28:29,609 ERROR [STDERR] at org.jboss.resource.connectionmanager.TxConnec
            tionManager.getManagedConnection(TxConnectionManager.java:317)
            09:28:29,609 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
            ectionManager2.allocateConnection(BaseConnectionManager2.java:469)
            09:28:29,656 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
            ectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.
            java:800)
            09:28:29,656 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSo
            urce.getConnection(WrapperDataSource.java:102)
            09:28:29,656 ERROR [STDERR] ... 32 more
            09:28:29,656 ERROR [STDERR] Caused by: java.sql.SQLException: [Microsoft][SQLSer
            ver 2000 Driver for JDBC]Error establishing socket.
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseExceptions.create
            Exception(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseExceptions.getExc
            eption(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseExceptions.getExc
            eption(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.sqlserver.tds.TDSConnectio
            n.(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.sqlserver.SQLServerImplCon
            nection.open(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseConnection.getNew
            ImplConnection(Unknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseConnection.open(U
            nknown Source)
            09:28:29,656 ERROR [STDERR] at com.microsoft.jdbc.base.BaseDriver.connect(Un
            known Source)
            09:28:29,656 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.local.LocalMa
            nagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.jav
            a:143)
            09:28:29,656 ERROR [STDERR] ... 40 more

            It's not exactly at 60 connections that I encountered the error, 65, 67, sometimes more than 80 connections. But if I get connections in this way in the getConnection() method:
            ......
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            conn = DriverManager.getConnection(...);
            return conn;
            ......
            then it works well. Should I make other configurations in jboss?

            • 3. Re: can't create a new connection
              Adrian Brock Master

              And what happens if you do that 80 times in a loop?

              Regards,
              Adrian

              • 4. Re: can't create a new connection
                kynix Newbie

                It still happens when I do that 80 times in a loop. But If it is less than 50 times, then everything is ok.

                • 5. Re: can't create a new connection
                  Adrian Brock Master

                  So your db cannot accept 80 connections.

                  Regards,
                  Adrian