public Integer call() throws Exception {
if ( startDelay > 0 ) {
Thread.sleep( startDelay );
}
AcrossContext context = createContext();
DistributedLockRepository distributedLockRepository = AcrossContextUtils.getBeanRegistry( context )
.getBeanOfType(
DistributedLockRepository.class );
ExecutorService fixedThreadPool = Executors.newFixedThreadPool( 50 );
List<Executor> executors = new ArrayList<>( LOCKS_PER_BATCH * EXECUTORS_PER_LOCK );
for ( int i = 0; i < LOCKS_PER_BATCH; i++ ) {
DistributedLock lock = distributedLockRepository.getLock( "batch-lock-" + i );
for ( int j = 0; j < EXECUTORS_PER_LOCK; j++ ) {
executors.add( new Executor( lock, 10 ) );
}
}
for ( Executor executor : executors ) {
fixedThreadPool.submit( executor );
}
fixedThreadPool.shutdown();
fixedThreadPool.awaitTermination( 3, TimeUnit.MINUTES );
int totalSucceeded = 0;
for ( Executor executor : executors ) {
if ( executor.isFinished() ) {
totalSucceeded++;
}
}
context.destroy();
return totalSucceeded;
}