2 Replies Latest reply on Apr 5, 2003 2:48 PM by samart

    Maxing out my managed connections?

    jabbott

      Hello jboss-

      I was having a problem with jboss 3.0.4 maxing out all the managed connections available and I found a posting stating that it was a bug with jboss 3.0.4. I was wanting to upgrade to jboss4 from cvshead. So I did thinking that the problem would be resolved with the upgrade. I was wrong.

      I'm still getting the same error. I'm running out of manage connections.

      I tried to attached my oracle-ds.xml and the class that is interacting with oracle. The form didn't seem to work.

      Here is one of my oracle datasource configurations.
      <local-tx-datasource>
      <jndi-name>oracleX1ds</jndi-name>
      <connection-url>jdbc:oracle:thin:@192.168.0.149:1521:x1</connection-url>
      <!--

      Here are a couple of the possible OCI configurations.
      For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm

      <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
      or
      <connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>

      Clearly, its better to have TNS set up properly.
      -->
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>picture</user-name>
      picture
      </local-tx-datasource>

      Here is the constructor where I grab the connections from the datasources. Note: this constructor is only called one time and the methods of this class are executed over and over again in a Thread.
      public showDbFacade() {
      cartMap = new Hashtable();
      x5ds = (DataSource)getObject( "oracleX5ds" );
      x1ds = (DataSource)getObject( "oracleX1ds" );
      try{
      x5con = x5ds.getConnection();
      x5ttcon = x5ds.getConnection();
      x1con = x1ds.getConnection();
      }
      catch( Exception e ){
      e.printStackTrace();
      }
      }

      Example Method:
      public byte[] getImage( final String prodID, final String blobType ){
      byte[] rbyt = null;
      String query = "select blob_data, blob_type "+
      "from new_image " +
      "where blob_type = ? " +
      "and product_id like ?";
      InputStream is = null;
      ByteArrayOutputStream baos = null;
      //Connection con = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      LiveLog.Write.debug("image.prodID-->"+getBaseID(prodID));
      try{
      if( x1con == null )
      x1con = x1ds.getConnection();
      else if ( x1con.isClosed() )
      x1con = x1ds.getConnection();
      ps = x1con.prepareStatement( query );
      if( prodID == null || prodID.equals("")) return null;
      if( blobType != null )
      ps.setString(1, blobType );
      else
      ps.setString(1, ".jpg" );
      if( prodID != null )
      ps.setString(2, getBaseID(prodID)+"%" );
      else
      return null;
      rs = ps.executeQuery();
      baos = new ByteArrayOutputStream();
      while( rs.next() ){
      Blob blob = rs.getBlob("blob_data");
      if( blob != null ){
      is = blob.getBinaryStream();
      byte[] b = new byte[128];
      int chunk = 0;
      while( (chunk = is.read(b) ) != -1 ){
      baos.write( b, 0, chunk );
      baos.flush();
      }
      is.close();
      is = null;
      }
      else{
      continue;
      }
      rbyt = baos.toByteArray();
      baos.close();
      baos = null;
      }
      return rbyt;
      }
      catch( Exception e ){
      e.printStackTrace();
      return rbyt;
      }
      finally{
      try{
      if( is != null )
      is.close();
      if( baos != null )
      baos.close();
      if( rs != null )
      rs.close();
      if( ps != null )
      ps.close();
      }
      catch( Exception e ){
      e.printStackTrace();
      }
      }
      }

      Here is my stacktrace..
      2003-04-02 08:17:02,125 ERROR [STDERR] org.jboss.util.NestedSQLException: No ManagedConnections Available!; - nested throwable: (javax.resource.ResourceException: No ManagedConnections Available!)
      2003-04-02 08:17:02,125 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:107)
      2003-04-02 08:17:02,140 ERROR [STDERR] at com.acntv.internet.live.server.showDbFacade.(showDbFacade.java:43)
      2003-04-02 08:17:02,140 ERROR [STDERR] at com.acntv.internet.live.server.liveDispatcher.getCartData(liveDispatcher.java:164)
      2003-04-02 08:17:02,140 ERROR [STDERR] at com.acntv.internet.live.server.liveDispatcher.doPost(liveDispatcher.java:82)
      2003-04-02 08:17:02,140 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
      2003-04-02 08:17:02,156 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      2003-04-02 08:17:02,156 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
      2003-04-02 08:17:02,156 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:280)
      2003-04-02 08:17:02,156 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
      2003-04-02 08:17:02,171 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)
      2003-04-02 08:17:02,171 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:549)
      2003-04-02 08:17:02,171 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)
      2003-04-02 08:17:02,171 ERROR [STDERR] at org.mortbay.http.HttpServer.service(HttpServer.java:863)
      2003-04-02 08:17:02,187 ERROR [STDERR] at org.jboss.jetty.Jetty.service(Jetty.java:497)
      2003-04-02 08:17:02,187 ERROR [STDERR] at org.mortbay.http.HttpConnection.service(HttpConnection.java:773)
      2003-04-02 08:17:02,187 ERROR [STDERR] at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:937)
      2003-04-02 08:17:02,187 ERROR [STDERR] at org.mortbay.http.HttpConnection.handle(HttpConnection.java:790)
      2003-04-02 08:17:02,203 ERROR [STDERR] at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
      2003-04-02 08:17:02,203 ERROR [STDERR] at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
      2003-04-02 08:17:02,203 ERROR [STDERR] at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
      2003-04-02 08:17:02,218 ERROR [STDERR] Caused by: javax.resource.ResourceException: No ManagedConnections Available!
      2003-04-02 08:17:02,218 ERROR [STDERR] at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:185)
      2003-04-02 08:17:02,218 ERROR [STDERR] at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool.getConnection(JBossManagedConnectionPool.java:580)
      2003-04-02 08:17:02,218 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:449)
      2003-04-02 08:17:02,234 ERROR [STDERR] at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:344)
      2003-04-02 08:17:02,234 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:519)
      2003-04-02 08:17:02,234 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:813)
      2003-04-02 08:17:02,250 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:103)
      2003-04-02 08:17:02,250 ERROR [STDERR] ... 19 more

        • 1. Re: Maxing out my managed connections?
          davidjencks

          I really have no idea what you are trying to do with this code or why.

          I recommend you use straightforward code where you

          get a connection
          use it
          close it in a finally block.

          Trying to outsmart the pooling, security, and tx mechanims are likely to break your app.

          • 2. Re: Maxing out my managed connections?
            samart

            i may be missing something, but you dont seem to be calling x1Con.close(). you have to return the connection to the pool, by calling con.close(), otherwise the pool will empty!!