From d3c3a3983f32533831d066edb50f4ac36072250b Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 2 Mar 2012 02:22:48 +0100 Subject: [PATCH] STS-2472: reduced the lock size when creating project classloaders --- .../core/java/ProjectClassLoaderCache.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/ProjectClassLoaderCache.java b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/ProjectClassLoaderCache.java index a333ca34b4..b498125776 100644 --- a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/ProjectClassLoaderCache.java +++ b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/ProjectClassLoaderCache.java @@ -300,29 +300,31 @@ private static boolean useNonLockingClassLoader() { * Returns a {@link ClassLoader} for the given project. */ @SuppressWarnings({ "unchecked" }) - protected synchronized static ClassLoader getClassLoader(IProject project, ClassLoader parentClassLoader) { - // Setup the root class loader to be used when no explicit parent class loader is given - if (parentClassLoader == null && cachedParentClassLoader == null) { - List paths = new ArrayList(); - Enumeration libs = SpringCore.getDefault().getBundle().getEntryPaths("/lib/"); - while (libs.hasMoreElements()) { - String lib = libs.nextElement(); - // Don't add the non locking classloader jar - if (!lib.contains("xbean-nonlocking-classloader")) { - paths.add(SpringCore.getDefault().getBundle().getEntry(lib)); + protected static ClassLoader getClassLoader(IProject project, ClassLoader parentClassLoader) { + synchronized (ProjectClassLoaderCache.class) { + // Setup the root class loader to be used when no explicit parent class loader is given + if (parentClassLoader == null && cachedParentClassLoader == null) { + List paths = new ArrayList(); + Enumeration libs = SpringCore.getDefault().getBundle().getEntryPaths("/lib/"); + while (libs.hasMoreElements()) { + String lib = libs.nextElement(); + // Don't add the non locking classloader jar + if (!lib.contains("xbean-nonlocking-classloader")) { + paths.add(SpringCore.getDefault().getBundle().getEntry(lib)); + } } + paths.addAll(JdtUtils.getBundleClassPath("com.springsource.org.aspectj.weaver")); + paths.addAll(JdtUtils.getBundleClassPath("com.springsource.org.objectweb.asm")); + paths.addAll(JdtUtils.getBundleClassPath("org.aopalliance")); + cachedParentClassLoader = new URLClassLoader(paths.toArray(new URL[paths.size()])); } - paths.addAll(JdtUtils.getBundleClassPath("com.springsource.org.aspectj.weaver")); - paths.addAll(JdtUtils.getBundleClassPath("com.springsource.org.objectweb.asm")); - paths.addAll(JdtUtils.getBundleClassPath("org.aopalliance")); - cachedParentClassLoader = new URLClassLoader(paths.toArray(new URL[paths.size()])); - } - if (project == null) { - return cachedParentClassLoader; - } + if (project == null) { + return cachedParentClassLoader; + } - registerListenersIfRequired(); + registerListenersIfRequired(); + } ClassLoader classLoader = findClassLoaderInCache(project, parentClassLoader); if (classLoader == null) {