Testing thread priority. How come in some cases low priority threads are faster?

后端 未结 2 1438
情书的邮戳
情书的邮戳 2021-01-22 10:57

I\'m trying to test 2 threads, one with high, and the other with low priority.

According to my results sometimes the low priority thread is faster, how is this possible?

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 11:20

    Thread priorities are not guaranteed to have any effect; this is mentioned in multiple places, including JDK javadocs. So assuming that on platform you are running on basically ignores levels, then it goes back to basic stastical probabilities: sometimes some threads seem to run faster than others, depending on how scheduler works and so on.

    I don't think anyone really uses Java thread priorities for everything, given that their working (or lack thereof) is at best platform-dependent.

提交回复
热议问题