Java Thread优先级如何转换为OS线程优先级? [英] How are Java Thread priorities translated to an OS thread priority?

查看:121
本文介绍了Java Thread优先级如何转换为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中的热点代码):

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

  • 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(不错值)

  • 1 – 10 ⇒ 4 – -5 (nice values)

值得注意的是,在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

  • 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 Thread优先级如何转换为OS线程优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆