boolean blocking,
long blockTimeout,
long trimInterval )
{
BufferedLogger logger = new BufferedLogger();
ResourceLimitingThreadPool pool = new ResourceLimitingThreadPool(
"Test Worker Pool", max, maxStrict, blocking, blockTimeout, trimInterval );
pool.enableLogging( logger );
Runnable runner = new Runnable()
{
public void run()
{
try
{
Thread.sleep( 200 );
}
catch( InterruptedException e )
{
}
incCompleteCount();
}
};
long start = System.currentTimeMillis();
m_completeCount = 0;
for( int i = 0; i < taskCount; i++ )
{
if( maxStrict && ( !blocking ) && i >= max )
{
// This request shoudl throw an exception.
try
{
pool.execute( runner );
fail( "Should have failed when requesting more than max resources." );
}
catch( Exception e )
{
// Ok
incCompleteCount();
}
}
else
{
pool.execute( runner );
}
}
long dur = System.currentTimeMillis() - start;
// Make sure that the size of the pool is what is expected.
assertEquals( "The pool size was not what it should be.", firstSize, pool.getSize() );
// Make sure this took about the right amount of time to get here.
//System.out.println( "First time: " + dur );
if( Math.abs( dur - firstTime ) > 500 )
{