Embed the listener interface in your task3 and register it for both task1 and task2. Task 1 and Task2 will have to call their listener before ending. That way you can write to task3, whose task has already been completed, and when both are done, you can complete your third task.
Of course, if you can exit your task 1/2 with an exception, do not forget to set task3 as your UncaughtExceptionHandler
source share