DecoratingClassLoader and its subclasses register themselves as parallel capable on Java 7+

Issue: SPR-12285
This commit is contained in:
Juergen Hoeller
2014-10-02 14:33:13 +02:00
parent 25d13ac41e
commit 05c995cfb3
5 changed files with 67 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,9 @@ package org.springframework.core;
import java.util.HashSet;
import java.util.Set;
import org.springframework.lang.UsesJava7;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Base class for decorating ClassLoaders such as {@link OverridingClassLoader}
@@ -30,8 +32,23 @@ import org.springframework.util.Assert;
* @author Rod Johnson
* @since 2.5.2
*/
@UsesJava7
public abstract class DecoratingClassLoader extends ClassLoader {
/**
* Java 7+ {@code ClassLoader.registerAsParallelCapable()} available?
* @since 4.1.2
*/
protected static final boolean parallelCapableClassLoaderAvailable =
ClassUtils.hasMethod(ClassLoader.class, "registerAsParallelCapable");
static {
if (parallelCapableClassLoaderAvailable) {
ClassLoader.registerAsParallelCapable();
}
}
private final Set<String> excludedPackages = new HashSet<String>();
private final Set<String> excludedClasses = new HashSet<String>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.core;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.lang.UsesJava7;
import org.springframework.util.FileCopyUtils;
/**
@@ -33,17 +34,23 @@ import org.springframework.util.FileCopyUtils;
* @author Juergen Hoeller
* @since 2.0.1
*/
@UsesJava7
public class OverridingClassLoader extends DecoratingClassLoader {
/** Packages that are excluded by default */
public static final String[] DEFAULT_EXCLUDED_PACKAGES =
new String[] {"java.", "javax.", "sun.", "oracle."};
public static final String[] DEFAULT_EXCLUDED_PACKAGES = new String[] {"java.", "javax.", "sun.", "oracle."};
private static final String CLASS_FILE_SUFFIX = ".class";
static {
if (parallelCapableClassLoaderAvailable) {
ClassLoader.registerAsParallelCapable();
}
}
/**
* Create a new OverridingClassLoader for the given class loader.
* Create a new OverridingClassLoader for the given ClassLoader.
* @param parent the ClassLoader to build an overriding ClassLoader for
*/
public OverridingClassLoader(ClassLoader parent) {