public static void runConcurrently(final Callable<Void> task,final int times) throws Exception {
  final ExecutorService service=Executors.newFixedThreadPool(5);
  final List<Future<?>> futures=new ArrayList<Future<?>>();
  for (int i=0; i < times; i++) {
    futures.add(service.submit(task));
  }
  for (  final Future<?> future : futures) {
    future.get();
  }
}

public static void runConcurrently ( final Callable < Void > task , final int times ) throws Exception { final ExecutorService service = Executors . newFixedThreadPool ( 5 ) ; final List < Future < ? > > futures = new ArrayList < Future < ? > > ( ) ; for ( int i = 0 ; i < times ; i ++ ) { futures . add ( service . submit ( task ) ) ; } for ( final Future < ? > future : futures ) { future . get ( ) ; } }
runs a task concurrently . allows to test thread - safe behavior .
