Thread.setContextClassLoader(ClassLoader cl) has the following syntax.
public void setContextClassLoader(ClassLoader cl)
In the following code shows how to use Thread.setContextClassLoader(ClassLoader cl) method.
public class Main { // ww w. ja va2 s. co m 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() { } }
The code above generates the following result.