You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2020/10/08 09:07:57 UTC
[sling-org-apache-sling-feature-launcher] branch master updated:
SLING-9802: protect the loadClass with the classloader lock and make the
LauncherClassloader parallel
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git
The following commit(s) were added to refs/heads/master by this push:
new f24d08b SLING-9802: protect the loadClass with the classloader lock and make the LauncherClassloader parallel
f24d08b is described below
commit f24d08bfd28c65908e113a3cf78a9a64c0d69d65
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Thu Oct 8 11:07:45 2020 +0200
SLING-9802: protect the loadClass with the classloader lock and make the LauncherClassloader parallel
---
.../sling/feature/launcher/spi/Launcher.java | 45 ++++++++++++----------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/launcher/spi/Launcher.java b/src/main/java/org/apache/sling/feature/launcher/spi/Launcher.java
index 79aa1dc..8c64ff0 100644
--- a/src/main/java/org/apache/sling/feature/launcher/spi/Launcher.java
+++ b/src/main/java/org/apache/sling/feature/launcher/spi/Launcher.java
@@ -33,6 +33,9 @@ public interface Launcher {
}
class LauncherClassLoader extends URLClassLoader {
+ static {
+ ClassLoader.registerAsParallelCapable();
+ }
public LauncherClassLoader() {
super(new URL[0]);
}
@@ -44,30 +47,32 @@ public interface Launcher {
@Override
public final Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- // First check if it's already loaded
- Class<?> clazz = findLoadedClass(name);
-
- if (clazz == null) {
-
- try {
- clazz = findClass(name);
- } catch (ClassNotFoundException cnfe) {
- ClassLoader parent = getParent();
- if (parent != null) {
- // Ask to parent ClassLoader (can also throw a CNFE).
- clazz = parent.loadClass(name);
- } else {
- // Propagate exception
- throw cnfe;
+ synchronized (getClassLoadingLock(name)) {
+ // First check if it's already loaded
+ Class<?> clazz = findLoadedClass(name);
+
+ if (clazz == null) {
+
+ try {
+ clazz = findClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ ClassLoader parent = getParent();
+ if (parent != null) {
+ // Ask to parent ClassLoader (can also throw a CNFE).
+ clazz = parent.loadClass(name);
+ } else {
+ // Propagate exception
+ throw cnfe;
+ }
}
}
- }
- if (resolve) {
- resolveClass(clazz);
- }
+ if (resolve) {
+ resolveClass(clazz);
+ }
- return clazz;
+ return clazz;
+ }
}
@Override