commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <joerg.schai...@gmx.de>
Subject Fwd: svn commit: r1000560 - in /commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub: AnnotationConfigurer.java AnnotationFactory.java
Date Sat, 25 Sep 2010 17:35:01 GMT
Hi Matt,

are you sure that this is a  good idea? In an AppServer environment the 
threads are pooled and therefore the ThreadLocal will keep the reference to 
the class loader. This will effectively prevent the classes from unloading 
when an application is redeployed.

- Jörg


--------------- Weitergeleitete Nachricht (Anfang)

Betreff: svn commit: r1000560 - in /commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub: 
AnnotationConfigurer.java AnnotationFactory.java
Absender: mbenson-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org
Datum: Thu, 23 Sep 2010 18:06:50 +0000
Newsgruppe: gmane.comp.jakarta.commons.scm

Author: mbenson
Date: Thu Sep 23 18:06:50 2010
New Revision: 1000560

URL: http://svn.apache.org/viewvc?rev=1000560&view=rev
Log:
clean up nested context code a bit + reuse classloader for children

Modified:
    commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java

[snip]

Modified: commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java?rev=1000560&r1=1000559&r2=1000560&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java 
(original)
+++ commons/proper/proxy/branches/version-2.0-
work/stub/src/main/java/org/apache/commons/proxy2/stub/AnnotationFactory.java 
Thu Sep 23 18:06:50 2010
@@ -25,6 +25,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 
 import org.apache.commons.lang3.AnnotationUtils;
+import org.apache.commons.lang3.Pair;
 import org.apache.commons.proxy2.Interceptor;
 import org.apache.commons.proxy2.Invocation;
 import org.apache.commons.proxy2.Invoker;
@@ -47,6 +48,12 @@ public class AnnotationFactory {
     /** Statically available instance */
     public static final AnnotationFactory INSTANCE;
 
+    /**
+     * Record the context of a call for possible use by nested annotation 
creations.
+     */
+    static final ThreadLocal<Pair<AnnotationFactory, ClassLoader>> CONTEXT =
+        new ThreadLocal<Pair<AnnotationFactory, ClassLoader>>();
+
     private static final ProxyFactory PROXY_FACTORY;
 
     static {


[snip]

@@ -256,8 +249,12 @@ public class AnnotationFactory {
 
     private <A extends Annotation> A createInternal(ClassLoader classLoader, 
Object configurer) {
         final Object existingConfigurer = CONFIGURER.get();
+        final boolean outerContext = CONTEXT.get() == null;
         try {
             CONFIGURER.set(configurer);
+            if (outerContext) {
+                CONTEXT.set(Pair.of(this, classLoader));
+            }
             @SuppressWarnings("unchecked")
             final A result = (A) proxyFactory.createInvokerProxy(classLoader, 
ANNOTATION_INVOKER, getStubType());
             return result;
@@ -267,6 +264,9 @@ public class AnnotationFactory {
             } else {
                 CONFIGURER.set(existingConfigurer);
             }
+            if (outerContext) {
+                CONTEXT.remove();
+            }
         }
     }
--------------- Weitergeleitete Nachricht (Ende)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message