/* * RE14.java * * Created on March 5, 2002, 9:17 AM */ import java.net.URLClassLoader; import java.net.URL; /** * * @author Jaroslav Tulach */ public class CntTest implements Runnable { public String name; public CntTest next; private Thread nextThread; public CntTest (String n) { name = n; } public synchronized void run () { try { System.out.println("name: " + name + " cnt: " + Thread.currentThread().getContextClassLoader()); if (next != null && nextThread == null) { nextThread = new Thread (next, name); nextThread.start (); } notify (); wait (); System.out.println("new context classloader: " + name + " is: " + Thread.currentThread ().getContextClassLoader ()); } catch (Exception ex) { ex.printStackTrace(); } } public static void main (String[] args) throws Exception { CntTest t1 = new CntTest ("t1"); CntTest t2 = new CntTest ("t2"); t1.next = t2; URLClassLoader l1 = new URLClassLoader (new URL[0]); URLClassLoader l2 = new URLClassLoader (new URL[0]); synchronized (t1) { synchronized (t2) { Thread t = new Thread (t1, "First"); t.setContextClassLoader (l1); t.start (); // waits for the values to be set t1.wait (); t2.wait (); t.setContextClassLoader (l2); // continues the second print t1.notify (); t2.notify (); } } } }