You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2007/05/11 15:20:50 UTC

svn commit: r537188 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: transport/http/HTTPConstants.java transport/http/HTTPSender.java util/threadpool/ThreadPool.java

Author: dims
Date: Fri May 11 06:20:49 2007
New Revision: 537188

URL: http://svn.apache.org/viewvc?view=rev&rev=537188
Log:
- Separate out the anonymous class for ThreadFactory into its own static inner class named DefaultThreadFactory
- If the user specified upper bound to # of threads then switch the algorithm to wait for a thread to become free and use it. By default, we create a new thread everytime.
- Add HTTPConstants.AUTO_RELEASE_CONNECTION parameter to automatically call releaseConnection for all the sendVia* methods to cleanup connections.
  (This is an effort to deal with AXIS2-935 and AXIS2-2593)
  

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/threadpool/ThreadPool.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java?view=diff&rev=537188&r1=537187&r2=537188
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java Fri May 11 06:20:49 2007
@@ -490,6 +490,11 @@
     public static final String OMIT_SOAP_12_ACTION = "OmitSOAP12Action";
     public static final String CUSTOM_PROTOCOL_HANDLER = "CUSTOM_PROTOCOL_HANDLER";
 
+    /*
+     * Automatically release connections.
+     */
+    public static final String AUTO_RELEASE_CONNECTION = "AutoReleaseConnection" ;
+
     /**
      * Method getBytes.
      *

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java?view=diff&rev=537188&r1=537187&r2=537188
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java Fri May 11 06:20:49 2007
@@ -21,6 +21,7 @@
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.MessageFormatter;
@@ -32,6 +33,7 @@
 import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -105,9 +107,16 @@
         } catch (IOException e) {
             log.info("Unable to sendViaGet to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
+        } finally {
+            cleanup(msgContext, getMethod);
         }
+    }
 
-
+    private void cleanup(MessageContext msgContext, HttpMethod method) {
+        Object autoClose = msgContext.getOptions().getProperty(HTTPConstants.AUTO_RELEASE_CONNECTION);
+        if (autoClose != null && JavaUtils.isTrueExplicitly(autoClose)) {
+            method.releaseConnection();
+        }
     }
 
     /**
@@ -131,8 +140,9 @@
         } catch (IOException e) {
             log.info("Unable to sendViaDelete to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
+        } finally {
+            cleanup(msgContext, deleteMethod);
         }
-
     }
 
     /**
@@ -183,8 +193,9 @@
         } catch (IOException e) {
             log.info("Unable to sendViaPost to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
+        } finally {
+            cleanup(msgContext, postMethod);
         }
-
     }
 
     /**
@@ -236,6 +247,8 @@
         } catch (IOException e) {
             log.info("Unable to sendViaPut to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
+        } finally {
+            cleanup(msgContext, putMethod);
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/threadpool/ThreadPool.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/threadpool/ThreadPool.java?view=diff&rev=537188&r1=537187&r2=537188
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/threadpool/ThreadPool.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/threadpool/ThreadPool.java Fri May 11 06:20:49 2007
@@ -18,6 +18,7 @@
 package org.apache.axis2.util.threadpool;
 
 import edu.emory.mathcs.backport.java.util.concurrent.Executor;
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
 import edu.emory.mathcs.backport.java.util.concurrent.SynchronousQueue;
 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
@@ -99,53 +100,59 @@
     protected ThreadPoolExecutor createDefaultExecutor(final String name,
                                                        final int priority,
                                                        final boolean daemon) {
-        ThreadPoolExecutor rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10,
-                                                       TimeUnit.SECONDS, new SynchronousQueue(),
-                                                       new edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory() {
-                                                           public Thread newThread(
-                                                                   final Runnable runnable) {
-                                                               // do the following section as privileged
-                                                               // so that it will work even when java2 security
-                                                               // has been enabled
-                                                               Thread returnThread = null;
-                                                               try {
-                                                                   returnThread =
-                                                                           (Thread) AccessController
-                                                                                   .doPrivileged(
-                                                                                           new PrivilegedExceptionAction() {
-                                                                                               public Object run() {
-                                                                                                   Thread newThread =
-                                                                                                           new Thread(
-                                                                                                                   runnable,
-                                                                                                                   name);
-                                                                                                   newThread
-                                                                                                           .setDaemon(
-                                                                                                                   daemon);
-                                                                                                   newThread
-                                                                                                           .setPriority(
-                                                                                                                   priority);
-                                                                                                   return newThread;
-                                                                                               }
-                                                                                           }
-                                                                                   );
-                                                               }
-                                                               catch (PrivilegedActionException e) {
-                                                                   // note: inner class can't have its own static log variable
-                                                                   if (log.isDebugEnabled()) {
-                                                                       log.debug(
-                                                                               "ThreadPoolExecutor.newThread():   Exception from AccessController [" +
-                                                                                       e.getClass()
-                                                                                               .getName() +
-                                                                                       "]  for [" +
-                                                                                       e.getMessage() +
-                                                                                       "]", e);
-                                                                   }
-                                                               }
-                                                               return returnThread;
-
-                                                           }
-                                                       });
+        ThreadPoolExecutor rc;
+        if (maxPoolSize == Integer.MAX_VALUE) {
+            rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10,
+                    TimeUnit.SECONDS, new SynchronousQueue(),
+                    new DefaultThreadFactory(name, daemon, priority));
+        } else {
+            rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10,
+                    TimeUnit.SECONDS, new LinkedBlockingQueue(),
+                    new DefaultThreadFactory(name, daemon, priority));
+        }
         rc.allowCoreThreadTimeOut(true);
         return rc;
+    }
+
+    private static class DefaultThreadFactory implements edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory {
+        private final String name;
+        private final boolean daemon;
+        private final int priority;
+
+        public DefaultThreadFactory(String name, boolean daemon, int priority) {
+            this.name = name;
+            this.daemon = daemon;
+            this.priority = priority;
+        }
+
+        public Thread newThread(
+                final Runnable runnable) {
+            // do the following section as privileged
+            // so that it will work even when java2 security
+            // has been enabled
+            Thread returnThread = null;
+            try {
+                returnThread = (Thread)
+                        AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                            public Object run() {
+                                Thread newThread =
+                                        new Thread(runnable, name);
+                                newThread.setDaemon(daemon);
+                                newThread.setPriority(priority);
+                                return newThread;
+                            }
+                        }
+                        );
+            }
+            catch (PrivilegedActionException e) {
+                // note: inner class can't have its own static log variable
+                if (log.isDebugEnabled()) {
+                    log.debug("ThreadPoolExecutor.newThread():   Exception from AccessController [" + e.getClass()
+                            .getName() + "]  for [" + e.getMessage() + "]", e);
+                }
+            }
+            return returnThread;
+
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org