public static <E>E syncRest(final Iterator<? extends Object> iterator,final Callable<E> task) throws Exception {
  if (iterator.hasNext()) {
synchronized (iterator.next()) {
      return syncRest(iterator,task);
    }
  }
 else {
    return task.call();
  }
}

public static < E > E syncRest ( final Iterator < ? extends Object > iterator , final Callable < E > task ) throws Exception { if ( iterator . hasNext ( ) ) { synchronized ( iterator . next ( ) ) { return syncRest ( iterator , task ) ; } } else { return task . call ( ) ; } }
recursively synchronizes on the components in the provided iterator and executes the provided task if there are no more components .
