????????????????
?????????????????????????????????????????????ClassLoader????????????????????????????????????????????????????????????????Щ?????????????????????硣
????????????????????????η?????????ClassLoader???loadClass??????????????????
????protected synchronized Class<?> loadClass(String name?? boolean resolve)
????throws ClassNotFoundException
????{
????// First?? check if the class has already been loaded
????Class c = findLoadedClass(name);
????if (c == null) {
????try {
????if (parent != null) {
????c = parent.loadClass(name?? false);
????} else {
????c = findBootstrapClassOrNull(name);
????}
????} catch (ClassNotFoundException e) {
????// ClassNotFoundException thrown if class not found
????// from the non-null parent class loader
????}
????if (c == null) {
????// If still not found?? then invoke findClass in order
????// to find the class.
????c = findClass(name);
????}
????}
????if (resolve) {
????resolveClass(c);
????}
????return c;
????}
????>1. Invoke findLoadedClass(String) to check if the class has already been loaded.
????>2. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built-in to the virtual machine is used?? instead.
????>3. Invoke the findClass(String) method to find the class.
???????????Javadoc????????????????????????????findClass?????
????Context ClassLoader
????????Java??ClassLoader?????????????Bootstrap ClassLoader??Ext ClassLoader??System ClassLoader?????????????????Context ClassLoader??????????μ??????????????????????????
??????????????????????????????A???????????????????????A???????B???????????????????(???B????б???????)??????????????B????????A??classpath???
???????????????????2??????????????????ClassLoader????????????????ClassLoaderC????????A?????????????????????ThreadB?У???ThreadB????ClassLoaderD??????????????A?????????????classpath??????????????????????Thread.currentThread().getContextClassLoader()???????????????ClassLoader????????ClassLoaderD??????????Thread.currentThread().setContextClassLoader(ClassLoader)??????????á?
??????????Contex ClassLoader
???????????Context ClassLoader?????Java??????“??????”???????о??????:
??????????????????:
????> JNDI?????JNDI????????bootstrap ClassLoader??rt.jar?м???????????JNDI????????????????????????????????????????-cp??????£???????????System ClassLoader????????????bootstartp ClassLoader????????SystemClassLoader????????????????????????????????parent????????????????Thread???????????????>Context ClassLoder ????????
???????????????????????????
????Contex ClassLoader??????????????????????
????Context ClassLoader??????Щ????????????????д?????????????ClassLoader???????