Skip to content

Commit

Permalink
Minor simplification and clarification.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias committed May 18, 2012
1 parent be8bf4d commit bdb5e8f
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -26,7 +26,6 @@
import org.jboss.logging.Logger; import org.jboss.logging.Logger;


import clojure.lang.Agent; import clojure.lang.Agent;
import clojure.lang.ArraySeq;
import clojure.lang.LockingTransaction; import clojure.lang.LockingTransaction;
import clojure.lang.RT; import clojure.lang.RT;
import clojure.lang.Symbol; import clojure.lang.Symbol;
Expand All @@ -45,9 +44,13 @@ protected void postInvoke(ClassLoader originalClassloader) {
try { try {
// leaving these thread locals around will cause memory leaks when the application // leaving these thread locals around will cause memory leaks when the application
// is undeployed. // is undeployed.
removeThreadLocal( LockingTransaction.class, "transaction" );
removeThreadLocal( Var.class, "dvals" ); removeThreadLocal( Var.class, "dvals" );

// this one doesn't leak, but leaving it set can theoretically allow another
// application to read the value off of the thread when it is doled out
//again from the pool
removeThreadLocal( Agent.class, "nested" ); removeThreadLocal( Agent.class, "nested" );
removeThreadLocal( LockingTransaction.class, "transaction" );
} catch (Exception e) { } catch (Exception e) {
log.error( "Failed to clear thread locals: ", e ); log.error( "Failed to clear thread locals: ", e );
} finally { } finally {
Expand All @@ -73,7 +76,7 @@ protected Var var(String namespacedFunction) {


@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected void removeThreadLocal( Class klass, String fieldName ) throws Exception { protected void removeThreadLocal( Class klass, String fieldName ) throws Exception {
Field field = lookupField( klass, fieldName, true ); Field field = lookupField( klass, fieldName );
if (field != null) { if (field != null) {
ThreadLocal tl = (ThreadLocal)field.get( null ); ThreadLocal tl = (ThreadLocal)field.get( null );
if (tl != null) { if (tl != null) {
Expand All @@ -83,7 +86,7 @@ protected void removeThreadLocal( Class klass, String fieldName ) throws Excepti
} }


@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected Field lookupField(Class klass, String fieldName, boolean makeAccessible) throws NoSuchFieldException { protected Field lookupField(Class klass, String fieldName) throws NoSuchFieldException {
Map<String, Field> fields = this.fieldCache.get( klass ); Map<String, Field> fields = this.fieldCache.get( klass );
if (fields == null) { if (fields == null) {
fields = new HashMap<String, Field>(); fields = new HashMap<String, Field>();
Expand All @@ -93,9 +96,7 @@ protected Field lookupField(Class klass, String fieldName, boolean makeAccessibl
Field field = fields.get( fieldName ); Field field = fields.get( fieldName );
if (field == null) { if (field == null) {
field = klass.getDeclaredField( fieldName ); field = klass.getDeclaredField( fieldName );
if (makeAccessible) { field.setAccessible( true );
field.setAccessible( true );
}
fields.put( fieldName, field ); fields.put( fieldName, field );
} }


Expand Down

0 comments on commit bdb5e8f

Please sign in to comment.