Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-4045

PooledInvokerProxy.getPooledConnection() could hold a lock for shorter period of time

    Details

    • Estimated Difficulty:
      Low

      Description

      Code from 4.0.3SP1
      =================
      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      while (pool.size() > 0)
      {
      socket = (ClientSocket)pool.removeFirst();
      try

      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }
      catch (Exception ex)
      {
      try
      { socket.socket.close(); }
      catch (Exception ignored) {}
      }
      }
      return null;
      }
      ===========================
      Should be changed to:

      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      synchronized (pool) {
      while (pool.size() > 0)
      {
      socket = (ClientSocket)pool.removeFirst();
      try
      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }

      catch (Exception ex)
      {
      try

      { socket.socket.close(); }
      catch (Exception ignored) {}
      }
      }
      }
      return null;
      }

      ===========================
      ....or perhaps better:

      protected ClientSocket getPooledConnection()
      {
      ClientSocket socket = null;
      while (pool.size() > 0)
      {
      try { socket = (ClientSocket)pool.removeFirst(); }
      catch (java.util.NoSuchElementException nsee)
      { return null; }

      try
      { // Test to see if socket is alive by send ACK message final byte ACK = 1; socket.out.writeByte(ACK); socket.out.flush(); socket.in.readByte(); return socket; }
      catch (Exception ex)
      {
      try
      { socket.socket.close(); }

      catch (Exception ignored) {}
      }
      }
      return null;
      }

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                smarlow Scott Marlow
                Reporter:
                smarlow Scott Marlow
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: