Thread.currentThread (). GetContextClassLoader ()
This is the current stream classloader and is independent of the class that calls it.
TestServlet.class.getClassLoader ()
This is the class loader that loaded the TestServlet class.
explain and also give an example of using these
Suppose you have Thread1 owned by ClassLoader1, and Thread2 owned by ClassLoader2. Perhaps you load your TestServlet class into Thread2 (using ClassLoader2) and then pass it to Thread1. At this point, if a TestServlet needs to load a Class belonging to ClassLoader1, it will need to use Thread.currentThread (). GetContextClassLoader () since its own ClassLoader is ClassLoader2, not ClassLoader1.
source share