I have a task. Before it starts all previous tasks should be finished.
For example, a graph with paths 1> 2> 4 and 1> 3> 4. Task 4 before starting should wait until 2 and 3 will be finished.
Each task should be completed only once. By default, task 4 is executed twice.
How can I do this with JAVA?