@Test public void testCCL() throws InterruptedException, IOException { final ClassLoader oldCcl = currentCcl(); try { final MyClassLoader myClassLoader = new MyClassLoader(); Thread.currentThread().setContextClassLoader(myClassLoader); final PerfLoggerClientThread thread = PerfLoggerClientThread.spawn(new InetSocketAddress("localhost", 0)); Thread.sleep(1000); final ClassLoader classLoaderInsideThread = thread.getContextClassLoader(); thread.done = true; thread.interrupt(); thread.join(); Assert.assertNotSame(myClassLoader, classLoaderInsideThread); } finally { Thread.currentThread().setContextClassLoader(oldCcl); } }
static PerfLoggerClientThread spawn(final InetSocketAddress socketAddress) { return AccessController.doPrivileged(new PrivilegedAction<PerfLoggerClientThread>() { @Override public PerfLoggerClientThread run() { final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); final PerfLoggerClientThread thread = new PerfLoggerClientThread(socketAddress); thread.start(); return thread; } finally { Thread.currentThread().setContextClassLoader(savedClassLoader); } } }); }
PerfLoggerClientThread extends Thread implements Closeable { static PerfLoggerClientThread spawn(final InetSocketAddress socketAddress) { return AccessController.doPrivileged(new PrivilegedAction<PerfLoggerClientThread>() { @Override public PerfLoggerClientThread run() { final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); final PerfLoggerClientThread thread = new PerfLoggerClientThread(socketAddress); thread.start(); return thread; } finally { Thread.currentThread().setContextClassLoader(savedClassLoader); } } }); } }
PerfLoggerClientThread extends Thread implements Closeable { static PerfLoggerClientThread spawn(final InetSocketAddress socketAddress) { return AccessController.doPrivileged(new PrivilegedAction<PerfLoggerClientThread>() { @Override public PerfLoggerClientThread run() { final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); final PerfLoggerClientThread thread = new PerfLoggerClientThread(socketAddress); thread.start(); return thread; } finally { Thread.currentThread().setContextClassLoader(savedClassLoader); } } }); } private  PerfLoggerClientThread(final InetSocketAddress socketAddress); }
PerfLoggerClientThread extends Thread implements Closeable { static PerfLoggerClientThread spawn(final InetSocketAddress socketAddress) { return AccessController.doPrivileged(new PrivilegedAction<PerfLoggerClientThread>() { @Override public PerfLoggerClientThread run() { final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); final PerfLoggerClientThread thread = new PerfLoggerClientThread(socketAddress); thread.start(); return thread; } finally { Thread.currentThread().setContextClassLoader(savedClassLoader); } } }); } private  PerfLoggerClientThread(final InetSocketAddress socketAddress); @Override void run(); @Override void close(); }
PerfLoggerClientThread extends Thread implements Closeable { static PerfLoggerClientThread spawn(final InetSocketAddress socketAddress) { return AccessController.doPrivileged(new PrivilegedAction<PerfLoggerClientThread>() { @Override public PerfLoggerClientThread run() { final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); final PerfLoggerClientThread thread = new PerfLoggerClientThread(socketAddress); thread.start(); return thread; } finally { Thread.currentThread().setContextClassLoader(savedClassLoader); } } }); } private  PerfLoggerClientThread(final InetSocketAddress socketAddress); @Override void run(); @Override void close();  }