This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 436b5d302c00a1fc797db09681f45a72e1e594aa Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Nov 24 12:25:50 2021 +0000 Align with 10.1.x - remove unnecessary synchronization --- .../catalina/core/DefaultInstanceManager.java | 42 +++++++++------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/java/org/apache/catalina/core/DefaultInstanceManager.java b/java/org/apache/catalina/core/DefaultInstanceManager.java index ee966de..588c367 100644 --- a/java/org/apache/catalina/core/DefaultInstanceManager.java +++ b/java/org/apache/catalina/core/DefaultInstanceManager.java @@ -224,13 +224,11 @@ public class DefaultInstanceManager implements InstanceManager { AnnotationCacheEntry[] annotations = annotationCache.get(clazz); for (AnnotationCacheEntry entry : annotations) { if (entry.getType() == AnnotationCacheEntryType.POST_CONSTRUCT) { + // This will always return a new Method instance + // Making this instance accessible does not affect other instances Method postConstruct = getMethod(clazz, entry); - synchronized (postConstruct) { - boolean accessibility = postConstruct.isAccessible(); - postConstruct.setAccessible(true); - postConstruct.invoke(instance); - postConstruct.setAccessible(accessibility); - } + postConstruct.setAccessible(true); + postConstruct.invoke(instance); } } } @@ -262,13 +260,11 @@ public class DefaultInstanceManager implements InstanceManager { } for (AnnotationCacheEntry entry : annotations) { if (entry.getType() == AnnotationCacheEntryType.PRE_DESTROY) { + // This will always return a new Method instance + // Making this instance accessible does not affect other instances Method preDestroy = getMethod(clazz, entry); - synchronized (preDestroy) { - boolean accessibility = preDestroy.isAccessible(); - preDestroy.setAccessible(true); - preDestroy.invoke(instance); - preDestroy.setAccessible(accessibility); - } + preDestroy.setAccessible(true); + preDestroy.invoke(instance); } } } @@ -571,7 +567,6 @@ public class DefaultInstanceManager implements InstanceManager { throws NamingException, IllegalAccessException { Object lookedupResource; - boolean accessibility; String normalizedName = normalize(name); @@ -582,12 +577,10 @@ public class DefaultInstanceManager implements InstanceManager { context.lookup(clazz.getName() + "/" + field.getName()); } - synchronized (field) { - accessibility = field.isAccessible(); - field.setAccessible(true); - field.set(instance, lookedupResource); - field.setAccessible(accessibility); - } + // This will always be a new Field instance + // Making this instance accessible does not affect other instances + field.setAccessible(true); + field.set(instance, lookedupResource); } /** @@ -613,7 +606,6 @@ public class DefaultInstanceManager implements InstanceManager { } Object lookedupResource; - boolean accessibility; String normalizedName = normalize(name); @@ -624,12 +616,10 @@ public class DefaultInstanceManager implements InstanceManager { clazz.getName() + "/" + Introspection.getPropertyName(method)); } - synchronized (method) { - accessibility = method.isAccessible(); - method.setAccessible(true); - method.invoke(instance, lookedupResource); - method.setAccessible(accessibility); - } + // This will always be a new Method instance + // Making this instance accessible does not affect other instances + method.setAccessible(true); + method.invoke(instance, lookedupResource); } private static void loadProperties(Set<String> classNames, String resourceName, --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org