[jboss-jira] [JBoss JIRA] Created: (JBAS-4045) PooledInvokerProxy.getPooledConnection() could hold a lock for shorter period of time

Scott Marlow (JIRA) jira-events at jboss.com
Thu Feb 1 13:48:19 EST 2007


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

                 Key: JBAS-4045
                 URL: http://jira.jboss.com/jira/browse/JBAS-4045
             Project: JBoss Application Server
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: Remoting
    Affects Versions: JBossAS-4.0.4RC1, JBossAS-4.0.3 SP1
            Reporter: Scott Marlow
         Assigned To: Scott M Stark
             Fix For: JBossAS-5.0.0.Beta1, JBossAS-4.0.5.CR1


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;
   }


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list