I'm looking for guidance for a problem logically equivalent to the following:
public boolean parallelOR() {
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<Boolean> taskA = executor.submit( new SlowTaskA() );
Future<Boolean> taskB = executor.submit( new SlowTaskB() );
return taskA.get() || taskB.get(); // This is not what I want
// Exception handling omitted for clarity
}
The above construction gives the correct result but always waits for taskA to complete even if the result is already known since taskB has completed.
Is there a better construction which will allow a value to be returned if either of the threads returns true without waiting for the second thread to complete?
(The platform involved is Android, if that affects the result).