ws-xmlrpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: xml-rpc/src/java/org/apache/xmlrpc XmlRpcServer.java
Date Fri, 25 Jan 2002 23:03:58 GMT
dlr         02/01/25 15:03:58

  Modified:    src/java/org/apache/xmlrpc XmlRpcServer.java
  Log:
  Merged in ideas from the patch by Timothy Peierls <tim@peierls.net>.
  Clearing the elements from the Vector instead of the entire Vector:
  
  The XmlRpcServer.Worker fields inParams, outParam, result, and
  strbuf are not being cleared on exit from the execute() method, and
  I believe they should be. All it takes is to wrap the execute() body
  with
  
      try {
          ...
      }
      finally {
          inParams = null;
          outParam = null;
          result = null;
          strBuf.setLength(0);
      }
  
  and remove the existing else clause that has "strBuf.setLength(0)".
  
  Even better, if outParam and result were made local variables
  instead of fields of Worker, you could remove the second and third
  lines of the finally clause.
  
  Why does this matter? Because there is no guarantee that the
  execute() method will be called again any time soon, or ever. Since
  there is no size restriction on arguments and results in the XML-RPC
  spec, you can have arbitrarily large objects hanging around for
  arbitrarily long intervals, a classic Java memory leak.
  
  I saw this happen in practice: The service defined a method to
  return the state of the entire system (as XML-RPC structs and
  arrays). Huge chunks of memory that could have been freed up on
  return were left dangling uselessly until the Worker was next used.
  Performance noticeably improved when we made a local fix to the
  Worker class.
  
  I asked about this over a year ago, but I think it got lost in the
  cracks.
  
  Revision  Changes    Path
  1.7       +28 -8     xml-rpc/src/java/org/apache/xmlrpc/XmlRpcServer.java
  
  Index: XmlRpcServer.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcServer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -u -r1.6 -r1.7
  --- XmlRpcServer.java	25 Jan 2002 22:38:20 -0000	1.6
  +++ XmlRpcServer.java	25 Jan 2002 23:03:58 -0000	1.7
  @@ -144,27 +144,46 @@
           }
       }
   
  -
  +    /**
  +     * Performs streaming, parsing, and handler execution.
  +     * Implementation is not thread-safe.
  +     */
       class Worker extends XmlRpc
       {
  -
           Vector inParams;
  -        Object outParam;
  -        byte[] result;
           StringBuffer strbuf;
  +        byte[] result;
   
  +        /**
  +         * Creates a new instance.
  +         */
  +        protected Worker()
  +        {
  +            inParams = new Vector();
  +            strbuf = new StringBuffer();
  +        }
  +
  +        /**
  +         * Given a request for the server, generates a response.
  +         */
           public byte[] execute (InputStream is, String user, String password)
           {
  -            inParams = new Vector ();
  -            if (strbuf == null)
  +            try
               {
  -                strbuf = new StringBuffer ();
  +                // Do the work
  +                return executeInternal(is, user, password);
               }
  -            else
  +            finally
               {
  +                // Release most of our resources
                   strbuf.setLength (0);
  +                inParams.removeAllElements();
               }
  +        }
   
  +        private byte[] executeInternal (InputStream is, String user,
  +                                        String password)
  +        {
               long now = System.currentTimeMillis ();
   
               try
  @@ -206,6 +225,7 @@
                                   methodName + "\": no default handler registered.");
                   }
   
  +                Object outParam;
                   if (handler instanceof AuthenticatedXmlRpcHandler)
                       outParam = ((AuthenticatedXmlRpcHandler) handler).
                               execute (methodName, inParams, user, password);
  
  
  

Mime
View raw message