You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2018/10/17 12:58:05 UTC

[cxf] branch 3.2.x-fixes updated: Only check for servlet 3.1 once. Class.forName is a synchonized (and expensive) call. Don't do it per-request.

This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
     new 8568f9a  Only check for servlet 3.1 once.  Class.forName is a synchonized (and expensive) call.  Don't do it per-request.
8568f9a is described below

commit 8568f9a8370e1ac1f029f89292705a93ed51e3e3
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Wed Oct 17 07:31:31 2018 -0400

    Only check for servlet 3.1 once.  Class.forName is a synchonized (and expensive) call.  Don't do it per-request.
---
 .../http/Servlet3ContinuationProvider.java         | 23 ++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
index 364364b..9492489 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
@@ -41,11 +41,22 @@ import org.apache.cxf.phase.PhaseInterceptorChain;
  *
  */
 public class Servlet3ContinuationProvider implements ContinuationProvider {
+    static final boolean IS_31;
+    static {
+        boolean is31 = false;
+        try {
+            ClassLoaderUtils.loadClass("javax.servlet.WriteListener", HttpServletRequest.class);
+            is31 = true;
+        } catch (Throwable t) {
+            is31 = false;
+        }
+        IS_31 = is31;
+    }
+    
     HttpServletRequest req;
     HttpServletResponse resp;
     Message inMessage;
     Servlet3Continuation continuation;
-    boolean is31;
 
     public Servlet3ContinuationProvider(HttpServletRequest req,
                                         HttpServletResponse resp,
@@ -53,14 +64,6 @@ public class Servlet3ContinuationProvider implements ContinuationProvider {
         this.inMessage = inMessage;
         this.req = req;
         this.resp = resp;
-        
-        
-        try {
-            ClassLoaderUtils.loadClass("javax.servlet.WriteListener", HttpServletRequest.class);
-            is31 = true;
-        } catch (Throwable t) {
-            is31 = false;
-        }
     }
 
     public void complete() {
@@ -78,7 +81,7 @@ public class Servlet3ContinuationProvider implements ContinuationProvider {
         }
 
         if (continuation == null) {
-            continuation = is31 ? new Servlet31Continuation() : new Servlet3Continuation();
+            continuation = IS_31 ? new Servlet31Continuation() : new Servlet3Continuation();
         } else {
             continuation.startAsyncAgain();
         }