in junit-addons/src/main/java/org/apache/directory/junit/tools/MultiThreadedMultiInvoker.java [124:188]
public Statement apply( final Statement base, final FrameworkMethod method, final Object target )
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
int count = numThreads;
if ( method.getAnnotation( NoMultiThreadedInvocation.class ) != null )
{
count = 1;
}
final long start = System.currentTimeMillis();
final List<Throwable> throwables = Collections.synchronizedList( new ArrayList<Throwable>() );
final List<Future<Void>> futures = new ArrayList<Future<Void>>();
for ( int threadNum = 0; threadNum < count; threadNum++ )
{
Callable<Void> c = new Callable<Void>()
{
public Void call() throws Exception
{
try
{
for ( int invocationNum = 0; invocationNum < numInvocationsPerThread; invocationNum++ )
{
if ( trace )
{
long t = System.currentTimeMillis() - start;
System.out.println( t + " - " + method.getName() + " - "
+ Thread.currentThread().getName() + " - Invocation "
+ ( invocationNum + 1 ) + "/" + numInvocationsPerThread );
}
base.evaluate();
}
}
catch ( Throwable t )
{
if ( trace )
{
t.printStackTrace();
}
throwables.add( t );
}
return null;
}
};
Future<Void> future = pool.submit( c );
futures.add( future );
}
for ( Future<Void> future : futures )
{
future.get();
}
if ( !throwables.isEmpty() )
{
throw throwables.get( 0 );
}
}
};
}