tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1172689 - /tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Date Mon, 19 Sep 2011 16:30:36 GMT
Author: markt
Date: Mon Sep 19 16:30:36 2011
New Revision: 1172689

URL: http://svn.apache.org/viewvc?rev=1172689&view=rev
Log:
Fix threading issue with changing visibility of methods and fields

Modified:
    tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java

Modified: tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java?rev=1172689&r1=1172688&r2=1172689&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java Mon Sep 19 16:30:36
2011
@@ -187,9 +187,11 @@ public class DefaultInstanceManager impl
             if (entry.getType() == AnnotationCacheEntryType.POST_CONSTRUCT) {
                 Method postConstruct = (Method) entry.getAccessibleObject();
                 boolean accessibility = postConstruct.isAccessible();
-                postConstruct.setAccessible(true);
-                postConstruct.invoke(instance);
-                postConstruct.setAccessible(accessibility);
+                synchronized (postConstruct) {
+                    postConstruct.setAccessible(true);
+                    postConstruct.invoke(instance);
+                    postConstruct.setAccessible(accessibility);
+                }
             }
         }
     }
@@ -229,9 +231,11 @@ public class DefaultInstanceManager impl
             if (entry.getType() == AnnotationCacheEntryType.PRE_DESTROY) {
                 Method preDestroy = (Method) entry.getAccessibleObject();
                 boolean accessibility = preDestroy.isAccessible();
-                preDestroy.setAccessible(true);
-                preDestroy.invoke(instance);
-                preDestroy.setAccessible(accessibility);
+                synchronized (preDestroy) {
+                    preDestroy.setAccessible(true);
+                    preDestroy.invoke(instance);
+                    preDestroy.setAccessible(accessibility);
+                }
             }
         }
     }
@@ -572,9 +576,11 @@ public class DefaultInstanceManager impl
         }
 
         accessibility = field.isAccessible();
-        field.setAccessible(true);
-        field.set(instance, lookedupResource);
-        field.setAccessible(accessibility);
+        synchronized (field) {
+            field.setAccessible(true);
+            field.set(instance, lookedupResource);
+            field.setAccessible(accessibility);
+        }
     }
 
     /**
@@ -614,9 +620,11 @@ public class DefaultInstanceManager impl
         }
 
         accessibility = method.isAccessible();
-        method.setAccessible(true);
-        method.invoke(instance, lookedupResource);
-        method.setAccessible(accessibility);
+        synchronized (method) {
+            method.setAccessible(true);
+            method.invoke(instance, lookedupResource);
+            method.setAccessible(accessibility);
+        }
     }
 
     public static String getName(Method setter) {



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


Mime
View raw message