How are Java Thread priorities translated to an OS thread priority?(Java 线程优先级如何转换为 OS 线程优先级?)
问题描述
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 线程优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 线程优先级如何转换为 OS 线程优先级?
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
