問題描述
Java API 線程優先級 (1-10) 如何轉換為操作系統級別的優先級,因為大多數操作系統沒有與此匹配的線程優先級(在數量方面).
How are the java API thread priorities (1-10) gets translated to the OS level priorities since most OS don't have thread priority levels (in terms of number) which match this.
因此請記住,是否存在兩個或多個具有不同優先級的線程最終在操作系統級別獲得相同優先級的情況.
So keeping in mind , can there be a scenario when two or more threads with different priorities eventually get the same priority at OS level.
請澄清,如果我的理解有一些更正.
Please clarify, if I there is some correction in my understanding.
推薦答案
確實,某些優先級可以映射到相同的本機"優先級.以下是列表(基于 OpenJDK 6 中的 Hotspot 代碼):
Indeed, some priority levels can map to the same "native" priority level. Here's the list (based on the Hotspot code in OpenJDK 6):
- 1 ? 0
- 2 ? 32
- 3 ? 64
- 4 ? 96
- 5 – 10 ? 127
值得注意的是,在 Solaris 上,您不能將線程優先級提高到高于正常水平,只能降低它:5 的優先級值與任何更高的值相同.
Of note is that on Solaris, you can't raise the thread priority above normal, only lower it: the priority value for 5 is the same as any of the higher values.
- 1 – 10 ? 4 – -5(
nice
值)
值得注意的是,在 Linux 上,Java 中不同的線程優先級確實映射到本機級別的不同優先級值.
Of note is that on Linux, different thread priorities in Java do map to distinct priority values at native level.
- 1 – 2 ?
THREAD_PRIORITY_LOWEST
- 3 – 4 ?
THREAD_PRIORITY_BELOW_NORMAL
- 5 – 6 ?
THREAD_PRIORITY_NORMAL
- 7 – 8 ?
THREAD_PRIORITY_ABOVE_NORMAL
- 9 – 10 ?
THREAD_PRIORITY_HIGHEST
這篇關于Java 線程優先級如何轉換為 OS 線程優先級?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!