Package org.apache.flink.util
Class FlinkUserCodeClassLoaders.SafetyNetWrapperClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.apache.flink.util.MutableURLClassLoader
-
- org.apache.flink.util.FlinkUserCodeClassLoaders.SafetyNetWrapperClassLoader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ClientWrapperClassLoader
- Enclosing class:
- FlinkUserCodeClassLoaders
@Internal public static class FlinkUserCodeClassLoaders.SafetyNetWrapperClassLoader extends MutableURLClassLoader
Ensures that holding a reference on the context class loader outliving the scope of user code does not prevent the user classloader to be garbage collected (FLINK-16245).This classloader delegates to the actual user classloader. Upon
close()
, the delegate is nulled and can be garbage collected. Additional class resolution will be resolved solely through the bootstrap classloader and most likely result in ClassNotFound exceptions.
-
-
Field Summary
Fields Modifier and Type Field Description protected FlinkUserCodeClassLoader
inner
-
Constructor Summary
Constructors Modifier Constructor Description protected
SafetyNetWrapperClassLoader(FlinkUserCodeClassLoader inner, ClassLoader parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addURL(URL url)
void
close()
MutableURLClassLoader
copy()
Copy the classloader for each job and these jobs can add their jar files to the classloader independently.URL
getResource(String name)
Enumeration<URL>
getResources(String name)
URL[]
getURLs()
Class<?>
loadClass(String name)
protected Class<?>
loadClass(String name, boolean resolve)
-
Methods inherited from class java.net.URLClassLoader
definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, newInstance, newInstance
-
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
inner
protected volatile FlinkUserCodeClassLoader inner
-
-
Constructor Detail
-
SafetyNetWrapperClassLoader
protected SafetyNetWrapperClassLoader(FlinkUserCodeClassLoader inner, ClassLoader parent)
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classURLClassLoader
-
loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
addURL
public void addURL(URL url)
- Overrides:
addURL
in classMutableURLClassLoader
-
copy
public MutableURLClassLoader copy()
Description copied from class:MutableURLClassLoader
Copy the classloader for each job and these jobs can add their jar files to the classloader independently.- Specified by:
copy
in classMutableURLClassLoader
- Returns:
- the copied classloader
-
getResource
public URL getResource(String name)
- Overrides:
getResource
in classClassLoader
-
getResources
public Enumeration<URL> getResources(String name) throws IOException
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
getURLs
public URL[] getURLs()
- Overrides:
getURLs
in classURLClassLoader
-
-