1 Reply Latest reply on Sep 29, 2010 9:08 AM by 670511

    Functor - detecting completion of all submitted Functors?

    653147
      I'm working with the example Functor code shown below. This code:

      for (int i = 0; i < 50; i++)
      *{*
      Future<Long> future = functorSubmitter.submitFunctor(contextIdentifier, new NextValueFunctor());
      System.out.println(future.get());
      *}*

      launches 50 asynchchronously executing instances of NextValueFunctor. In order to make use of returned values from ALL of those instances, I would need to know when they have all completed execution. The example code continues and does this:


      Thread.sleep(2000);
      Counter counter = (Counter) contextsManager.getContext(contextIdentifier);
      System.out.println(counter);

      CacheFactory.shutdown();

      It appears to me as though the code is written to assume that all instances will have completed within 2 seconds. I'd like to be more certain, however. Is there any way I can know when all submitted instances have completed execution?

      Thanks !!






      For reference, this is the example code I am asking about:

      *public class FunctorPatternExample {*
      *public static void main(String[] args) throws InterruptedException, ExecutionException {*
           
      ContextsManager contextsManager = DefaultContextsManager.getInstance();
      Identifier contextIdentifier = contextsManager.registerContext("myCounter", new Counter(0));
                
      FunctorSubmitter functorSubmitter = DefaultFunctorSubmitter.getInstance();
      functorSubmitter.submitCommand(contextIdentifier, new LoggingCommand("Commenced", 0));

      *for (int i = 0; i < 50; i++) {*
      Future<Long> future = functorSubmitter.submitFunctor(contextIdentifier, new NextValueFunctor());
      System.out.println(future.get());
      *}*
                
      functorSubmitter.submitCommand(contextIdentifier, new LoggingCommand("Completed", 0));
                
      Thread.sleep(2000);
                
      Counter counter = (Counter)contextsManager.getContext(contextIdentifier);
      System.out.println(counter);
      *}*