is it possible to define execution order for a set of threads in java

后端 未结 6 1796
离开以前
离开以前 2021-01-26 00:10

My understanding is that threads in theory are executed in parallel. JVM decides; when a resource is available which thread to pick from the waiting thread queue (based on some

6条回答
  •  逝去的感伤
    2021-01-26 00:43

    Use an Executor:

    executor.execute(runnable1);
    wait();
    executor.execute(runnable2);
    wait();
    executor.execute(runnable3);
    wait();
    

    And of course, each Runnable has to end with a notify() statement.

提交回复
热议问题