Java Thread .setContextClassLoader (ClassLoader cl)
Syntax
Thread.setContextClassLoader(ClassLoader cl) has the following syntax.
public void setContextClassLoader(ClassLoader cl)
Example
In the following code shows how to use Thread.setContextClassLoader(ClassLoader cl) method.
public class Main {
// w ww. j av a 2 s. c om
public static void main(String args[]) {
new ThreadDemo();
}
}
class ThreadDemo implements Runnable {
ThreadDemo() {
Thread t = new Thread(this);
t.start();
ClassLoader c = t.getContextClassLoader();
// sets the context ClassLoader for this Thread
t.setContextClassLoader(c);
System.out.println("Class = " + c.getClass());
System.out.println("Parent = " + c.getParent());
}
public void run() {
}
}