You need to send tasks in two batches or create an explicit βhappen soonerβ relationship. Offer to create two batches of tasks and using invokeAll(batch1); invokeAll(batch2); invokeAll(batch1); invokeAll(batch2); The invokeAll() method invokeAll() complete all tasks and lock them until completion. You may need to wrap Runnable as Callable s, which you can do with Executors.callable(Runnable r) . (@Cameron Skinner beat me to get sample code, see this answer for more ...)
The whole point of the performers is to abstract from the specifics of the performance, so ordering is not guaranteed unless explicitly stated. If you want strictly sequential execution, do it in the thread you are working in (the simplest), do it in a single-threaded executor, ala Executors.newSingleThreadExecutor() or explicitly synchronize tasks. If you want to do the latter, you can use a barrier or latch and block dependent tasks on the barrier / latch. You can also implement the first block of Callable tasks, return Future and call the dependent tasks myFuture.get() , which would force them to block until the results are returned.
If you say more about your specific application, we can help more specifically.
source share