Quoting javadoc ExecutorService :
Memory consistency effects: Actions in the thread before sending the Runnable or Callable to the ExecutorService occur before any actions taken by this task, which in turn occurs - until the result is received via Future.get() .
But it does not say anything about the two tasks added to the queue, and whether the processing of task 1 is in progress before processing task 2, as can be seen from the task. It’s just that the task is added to the queue before the task is processed, and the task is completed before the result is received by the initial call.
Update
It doesn’t happen - until the correlation between two different independently assigned tasks, even if it is known that the launch is completed before the other starts working.
Of course, when one task sends another, as is done in the question, any action taken in task 1 before sending task 2 will occur before task 2 is completed.
If task 1 continues to do other things after sending task 2, then of course nothing happens - before the guarantee, because task 2 can be completed and completed before task 1 continues to work.
source share