assertEquals(200, used);
}
public void testMultipleRecursiveWithThreads() throws Exception
{
final ThreadlocalPool pool = new ThreadlocalPool();
Container container = new MockContainer();
int maxSize = -1;
int timeout = -1;
pool.initialize(container, maxSize, timeout);
Runnable r = new Runnable()
{
public void run()
{
for(int i = 0; i < 10; i++)
{
BeanContext ctx = pool.get();
BeanContext ctx2 = pool.get();
pool.release(ctx2);
ctx2 = null;
used ++;
pool.release(ctx);
ctx = null;
used ++;
}
}
};
Thread threads[] = new Thread[20];
for(int i = 0; i < threads.length; i++)
{
threads[i] = new Thread(r);
threads[i].start();
}
for(Thread t : threads)
{
t.join(1000);
}
gc();
assertEquals(200, pool.getRemoveCount());
assertEquals(200, MockBean.finalizers);
pool.destroy();
gc();
assertEquals(220, pool.getRemoveCount());
assertEquals(220, MockBean.finalizers);
assertEquals(400, used);
}