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

后端 未结 6 1919
离开以前
离开以前 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:24

    Don't use threads, is the straightforward answer.

    If you don't want code to run out of order, then why are you using threads at all? Just execute things step by step like normal.

    If you want certain parts of the threads to run in order, then use standard concurrency mechanisms like locks, wait/notify, and semaphores, but if you just want whole operations to run in a specific order, then...run them in order. Without threads.

提交回复
热议问题