@@ -29,16 +29,27 @@ import org.apache.spark.util.ParentClassLoader
2929 * The addURL method in URLClassLoader is protected. We subclass it to make this accessible.
3030 * We also make changes so user classes can come before the default classes.
3131 */
32-
3332private [spark] trait MutableURLClassLoader extends ClassLoader {
3433 def addURL (url : URL )
3534 def getURLs : Array [URL ]
3635}
3736
37+ /**
38+ * A class loader that gives preference to its own URLs over the parent class loader
39+ * when loading classes and resources.
40+ */
3841private [spark] class ChildExecutorURLClassLoader (urls : Array [URL ], parent : ClassLoader )
3942 extends URLClassLoader (urls, null ) with MutableURLClassLoader {
4043
4144 private val parentClassLoader = new ParentClassLoader (parent)
45+
46+ /**
47+ * Used to implement fine-grained class loading locks similar to what is done by Java 7. This
48+ * prevents deadlock issues when using non-hierarchical class loaders.
49+ *
50+ * Note that due to Java 6 compatibility (and some issues with implementing class loaders in
51+ * Scala), Java 7's `ClassLoader.registerAsParallelCapable` method is not called.
52+ */
4253 private val locks = new ConcurrentHashMap [String , Object ]()
4354
4455 override def loadClass (name : String , resolve : Boolean ): Class [_] = {
@@ -84,6 +95,9 @@ private[spark] class ChildExecutorURLClassLoader(urls: Array[URL], parent: Class
8495
8596}
8697
98+ /**
99+ * A MutableURLClassLoader that follows the standard parent-first hierarchy.
100+ */
87101private [spark] class ExecutorURLClassLoader (urls : Array [URL ], parent : ClassLoader )
88102 extends URLClassLoader (urls, parent) with MutableURLClassLoader {
89103
0 commit comments