How threads work in Java and how their working is different from basic code inside a method?

前端 未结 4 1407
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 10:11

Basically this code has two threads created in two classes, and they are called from the third class. Each thread has a loop, and it sleeps after each iteration.

(co

4条回答
  •  天命终不由人
    2020-12-10 10:47

    You can't predict in which order threads will be executed unless you control their execution (with mechanism like lock, mutex, semaphore and join).

    I think you need more knowledge about concurrency programming.

    Here some useful links:

    wikipedia's concurrency page

    oracle's tutorial (IMHO it's pretty good tutorial)

提交回复
热议问题