openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1679831 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Date Sun, 17 May 2015 10:05:29 GMT
Author: struberg
Date: Sun May 17 10:05:29 2015
New Revision: 1679831

URL: http://svn.apache.org/r1679831
Log:
OWB-1048 ThreadLocals must not be static. 

Otherwise we get into troubles supporting EARs which have a 
parent ClassLoader structure with their own Contexts probably.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java?rev=1679831&r1=1679830&r2=1679831&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ExceptionUtil.java
Sun May 17 10:05:29 2015
@@ -25,6 +25,10 @@ public abstract class ExceptionUtil
         // prevent instantiation
     }
 
+    /**
+     * Throws the given Exception as RuntimeException
+     * @return null; this is just for IDEs to allow them detect the end of the control flow
+     */
     public static RuntimeException throwAsRuntimeException(Throwable throwable)
     {
         //Attention: helper which allows to use a trick to throw
@@ -33,6 +37,22 @@ public abstract class ExceptionUtil
         return null; //not needed due to the helper trick, but it's easier for using it
     }
 
+
+    /**
+     * This is for debugging/logging purpose only!
+     * @return The stack trace of the current Thread.
+     */
+    public static String currentStack()
+    {
+        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+        StringBuilder sb = new StringBuilder(500);
+        for (StackTraceElement ste : stackTrace)
+        {
+            sb.append("  ").append(ste.getClassName()).append("#").append(ste.getMethodName()).append(":").append(ste.getLineNumber()).append('\n');
+        }
+        return sb.toString();
+    }
+
     @SuppressWarnings({ "unchecked" })
     private static class ExceptionHelper<T extends Throwable>
     {

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1679831&r1=1679830&r2=1679831&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Sun May 17 10:05:29 2015
@@ -70,12 +70,6 @@ public class WebContextsService extends
      */
     private final boolean destroySessionImmediately = false;
 
-    /**Current request context*/
-    protected static ThreadLocal<ServletRequestContext> requestContexts = null;
-
-    /**Current session context*/
-    protected static ThreadLocal<SessionContext> sessionContexts = null;
-
     /**
      * A single applicationContext
      */
@@ -83,11 +77,17 @@ public class WebContextsService extends
 
     protected SingletonContext singletonContext;
 
+    /**Current request context*/
+    protected ThreadLocal<ServletRequestContext> requestContexts = null;
+
+    /**Current session context*/
+    protected ThreadLocal<SessionContext> sessionContexts = null;
+
     /**Current conversation context*/
-    protected static ThreadLocal<ConversationContext> conversationContexts = null;
+    protected ThreadLocal<ConversationContext> conversationContexts = null;
     
     /**Current dependent context*/
-    protected static DependentContext dependentContext;
+    protected DependentContext dependentContext;
 
     /**Conversation context manager*/
     protected final ConversationManager conversationManager;
@@ -97,18 +97,6 @@ public class WebContextsService extends
 
 
 
-    /**Initialize thread locals*/
-    static
-    {
-        requestContexts = new ThreadLocal<ServletRequestContext>();
-        sessionContexts = new ThreadLocal<SessionContext>();
-        conversationContexts = new ThreadLocal<ConversationContext>();
-
-        //Dependent context is always active
-        dependentContext = new DependentContext();
-        dependentContext.setActive(true);
-    }
-
     /**
      * Creates a new instance.
      */
@@ -120,6 +108,14 @@ public class WebContextsService extends
         applicationContext = new ApplicationContext();
         applicationContext.setActive(true);
 
+        requestContexts = new ThreadLocal<ServletRequestContext>();
+        sessionContexts = new ThreadLocal<SessionContext>();
+        conversationContexts = new ThreadLocal<ConversationContext>();
+
+        //Dependent context is always active
+        dependentContext = new DependentContext();
+        dependentContext.setActive(true);
+
         configureEagerSessionInitialisation(webBeansContext);
     }
 



Mime
View raw message