This discussion is archived
1 Reply Latest reply: Sep 29, 2010 2:08 AM by 670511 RSS

Functor - detecting completion of all submitted Functors?

653147 Newbie
Currently Being Moderated
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);
*}*

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points