throws Exception
{
int numThreads = 8;
int numLoops = 100;
Semaphore semaphore = new Semaphore(numThreads);
ThreadGroup runnerGroup = new ThreadGroup("TestRunners");
ClassLoader ours = Thread.currentThread().getContextClassLoader();
// The classloader we want channel threads to use
ClassLoaderLeakHandler handler = new ClassLoaderLeakHandler(testLoader, semaphore, runnerGroup);
MessageDispatcher[] dispatchers = new MessageDispatcher[2];
// Thread.currentThread().setContextClassLoader(testLoader);
// try
// {
channel1 = (Channel) factoryMeth.invoke(factory1, factory1Args);
dispatchers[0] = new MessageDispatcher(channel1, handler, handler, handler);
channel1.connect("leaktest");
assertEquals("No classloader leak on channel1 connect", null, handler.getLeakedClassLoader());
channel2 = (Channel) factoryMeth.invoke(factory2, factory2Args);
dispatchers[1] = new MessageDispatcher(channel2, handler, handler, handler);
channel2.connect("leaktest");
assertEquals("No classloader leak on channel2 connect", null, handler.getLeakedClassLoader());
// }
// finally
// {
// Thread.currentThread().setContextClassLoader(ours);
// }
log.info("Channels connected");
ClassLoaderLeakRunner[] runners = new ClassLoaderLeakRunner[numThreads];
for (int i = 0; i < runners.length; i++)
{
MessageDispatcher disp = dispatchers[i % 2];
runners[i] = new ClassLoaderLeakRunner(disp, numLoops, runnerGroup, semaphore);
}
semaphore.acquire(numThreads);
for (int i = 0; i < runners.length; i++)
{
runners[i].start();
}
semaphore.release(numThreads);
try
{
assertTrue("messages received within 15 seconds", semaphore.tryAcquire(numThreads, 15, TimeUnit.SECONDS));
log.info("Messages received");
}
finally
{