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() {

  }

}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable