Understanding java.lang.Thread.State: WAITING (parking)

前端 未结 5 592
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 11:42

First, a really dumb question, I was just wondering what the waiting \'parking\' means ? Is the thread waiting to be parked or is it just been parked and therefore is in wai

5条回答
  •  再見小時候
    2020-12-07 12:25

    As i understand it, the "permit" is just an object that represent if a Thread can be "unparked" or not. And this is checked by the Thread itself (or de JRE when you try to park a Thread) The "is consumed" thing, i understand that the permit dissapears and the Thread is not dissabled.

    I think you should learn a little bit more about multithreading.. Think of it as a dispenser with Objects called "permit". You tell to a Thread to park, and the Thread check the dispenser, if there is a "permit", the Thread take it and leaves(without park). If there is no "permit" in the dispenser the Thread is parked until a "permit" is avaliable (and you can put a "permit" in the dispenser with unpark.

    As for the CPU/memory usage, i think that depends of the OS, etc...

提交回复
热议问题