wro4j-core/src/main/java/ro/isdc/wro/util/concurrent/TaskExecutor.java
public void submit(final Collection<Callable<T>> callables)
      throws Exception {
    Validate.notNull(callables);

    final StopWatch watch = new StopWatch();
    watch.start("init");
    final long start = System.currentTimeMillis();
    final AtomicLong totalTime = new AtomicLong();
    LOG.debug("running {} tasks", callables.size());

    if (callables.size() == 1) {
      final T result = callables.iterator().next().call();
      onResultAvailable(result);
    } else {
      LOG.debug("Running tasks in parallel");
      watch.stop();

      watch.start("submit tasks");
      for (final Callable<T> callable : callables) {
        getCompletionService().submit(decorate(callable, totalTime));
      }
      watch.stop();

      watch.start("consume results");
      for (int i = 0; i < callables.size(); i++) {
        doConsumeResult();
      }
    }
    watch.stop();
    destroy();

    LOG.debug("Number of Tasks: {}", callables.size());
    final long averageExecutionTime = callables.size() != 0 ? totalTime.longValue() / callables.size() : 0;
    LOG.debug("Average Execution Time: {}", averageExecutionTime);
    LOG.debug("Total Task Time: {}", totalTime);
    LOG.debug("Grand Total Execution Time: {}", System.currentTimeMillis() - start);
    LOG.debug(watch.prettyPrint());
  }
public void submit(final Collection<Callable<T>> callables)
      throws Exception {
    Validate.notNull(callables);

    final StopWatch watch = new StopWatch();
    watch.start("init");
    final long start = System.currentTimeMillis();
    final AtomicLong totalTime = new AtomicLong();
    LOG.debug("running {} tasks", callables.size());

    if (callables.size() == 1) {
      final T result = callables.iterator().next().call();
      onResultAvailable(result);
    } else {
      LOG.debug("Running tasks in parallel");
      watch.stop();

      watch.start("submit tasks");
      for (final Callable<T> callable : callables) {
        getCompletionService().submit(decorate(callable, totalTime));
      }
      watch.stop();

      watch.start("consume results");
      for (int i = 0; i < callables.size(); i++) {
        doConsumeResult();
      }
    }
    watch.stop();
    destroy();

    LOG.debug("Number of Tasks: {}", callables.size());
    final long averageExecutionTime = callables.size() != 0 ? totalTime.longValue() / callables.size() : 0;
    LOG.debug("Average Execution Time: {}", averageExecutionTime);
    LOG.debug("Total Task Time: {}", totalTime);
    LOG.debug("Grand Total Execution Time: {}", System.currentTimeMillis() - start);
    LOG.debug(watch.prettyPrint());
  }
public void submit ( final Collection < Callable < T > > callables ) throws Exception { Validate . notNull ( callables ) ; final StopWatch watch = new StopWatch ( ) ; watch . start ( "init" ) ; final long start = System . currentTimeMillis ( ) ; final AtomicLong totalTime = new AtomicLong ( ) ; LOG . debug ( "running {} tasks" , callables . size ( ) ) ; if ( callables . size ( ) == 1 ) { final T result = callables . iterator ( ) . next ( ) . call ( ) ; onResultAvailable ( result ) ; } else { LOG . debug ( "Running tasks in parallel" ) ; watch . stop ( ) ; watch . start ( "submit tasks" ) ; for ( final Callable < T > callable : callables ) { getCompletionService ( ) . submit ( decorate ( callable , totalTime ) ) ; } watch . stop ( ) ; watch . start ( "consume results" ) ; for ( int i = 0 ; i < callables . size ( ) ; i ++ ) { doConsumeResult ( ) ; } } watch . stop ( ) ; destroy ( ) ; LOG . debug ( "Number of Tasks: {}" , callables . size ( ) ) ; final long averageExecutionTime = callables . size ( ) != 0 ? totalTime . longValue ( ) / callables . size ( ) : 0 ; LOG . debug ( "Average Execution Time: {}" , averageExecutionTime ) ; LOG . debug ( "Total Task Time: {}" , totalTime ) ; LOG . debug ( "Grand Total Execution Time: {}" , System . currentTimeMillis ( ) - start ) ; LOG . debug ( watch . prettyPrint ( ) ) ; }
TODO rename to submitAll.
<p/>
Submits a chunk of jobs for parallel execution. This is a blocking operation - it will end execution when all
submitted tasks are finished.

@param callables
a {@link Collection} of {@link Callable} to execute. When the provided collection contains only one item,
the task will be executed synchronously.
@throws Exception
if an exception occurred during callable execution.
TODO rename to submitAll . <p / > Submits a chunk of jobs for parallel execution . This is a blocking operation - it will end execution when all submitted tasks are finished .