我读到线程优先级算法的正确性并不总是有保证的,因为它依赖于JVM。为什么会这样?它是如何依赖于JVM的?
提前谢谢。
发布于 2014-12-15 18:00:41
线程优先级效果是特定于平台的。应该避免使用这些优先级,因为它们可能会导致活性问题,并且它们的效果并不明显。
来自实践中的Java并发性:
The thread priorities defined in the Thread API are merely scheduling hints.The Thread
API defines ten priority levels that the JVM can map to operating system scheduling
priorities as it sees fit. This mapping is platform‐specific, so two Java priorities
can map to the sameOS priority on one system and different OS priorities on another.
...
The thread priority mechanism is a blunt instrument, and it's not always obvious what
effect changing priorities will have; boosting a thread's priority might do nothing or
might always cause one thread to be scheduled in preference to the other, causing
starvation.结论:
Avoid the temptation to use thread priorities, since they increase platform
dependence and can cause liveness problems. Most concurrent applications can use
the default priority for all threads.https://stackoverflow.com/questions/27479385
复制相似问题