I am using an ExecutorService to submit my Callable tasks and get Future objects from them.
My question is: can I submit a new task to the executor that needs the result of a future object from an other task completion?
while (someCondition){
Future<Type1> f1 = executor.submit(new SomeCallable1(Type1_istance));
try {
Future<Type2> f2 = executor.submit(new SomeCallable2(f1));
} catch (InterruptedException | ExecutionException e) {
...
}
SomeCallable2 is like:
public void call(){ Type1 a = f1.get(); ...; //use a somehow }
the thread running SomeCollable2 call() should sleep until f1 is ready, right?
A lot of exception raised when i tried my code and I don't understand if they're because I am using Futures in the wrong way or not.