Ensure that code within CompletableFuture callback executes after
问题 Say I have this: public void foo(){ CompletableFuture.delayedExecutor(1, TimeUnit.MILLISECONDS).execute(() -> { doSomethingA(); }); doSomethingB(); } Is there any guarantee that doSomethingB(); will always run before doSomethingA();? Something tells me with thread pre-emption , it's possible, although unlikely, that doSomethingA() could be run first? 回答1: No, there is no guarantee, when on a machine which has multiple processors, that doSomethingB() would always execute before doSomethingA().