Java Thread .getContextClassLoader ()
Syntax
Thread.getContextClassLoader() has the following syntax.
public ClassLoader getContextClassLoader()
Example
In the following code shows how to use Thread.getContextClassLoader() method.
/*from w ww . ja va 2 s.c o m*/
class ThreadDemo extends Thread {
public void run() {
// returns the context ClassLoader for this Thread
ClassLoader c = getContextClassLoader();
// sets the context ClassLoader for this Thread
setContextClassLoader(c);
System.out.println("Class = " + c.getClass());
System.out.println("Parent = " + c.getParent());
}
}
public class Main {
public static void main(String args[]) {
ThreadDemo t = new ThreadDemo();
// this will call run() function
t.start();
}
}