In which scenario will we use Thread.getContextClassLoader () and ClassLoader.getSystemClassLoader () can set it?

After going through google, I really couldn't find an example using Thread.getContextClassLoader (),

Perhaps this question is repeated as shown below. Difference between thread context classloader and regular classloader

My question is below: Since I know the scenario for using Thread.getContextLoader, the Becasue JNDI base classes included in /lib/rt.jar but these JNDI Core (maybe this is just some interface) are not implemented by the bean, in other cases if you want to use JNDI functions you have to provide JNDI implementation, then we put this implementation (maybe jars) in the system classpath, but now the JDNI core classes are loaded by Bootstrap, and these base classes should use their implementation classes.Okay, we supply Thread. getContextClassLoader () (if you dont have any default operations this is ClassLoader.getSystemClassLoader ()) for it, it can load them now, I just assumed that why the main JNDI classes use this way to get systemClassLoader 'ClassLoader.getSystemClassLoader () 'directly?

Perhaps I did not explain some points correctly.

<1>, but I just want to understand if we can use the ClassLoader.getSystemClassLoader () instand Thread.getClassLoader () for the loader. Classes of classpaths or resouces in classes that are loaded by bootstrap bootloader?

+3


source to share


1 answer


Thread.getContextClassLoader()

was not introduced to java from the very beginning. This is very useful in multi-class environments, soon for Java EE applications running in a container, which would usually distribute a private class loader for each enterprise application. Thus, the resources packaged with this application can be retrieved using the context class loader.



It is also used to self-configure logging systems such as community and log4j logging.

+1


source







All Articles