Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

multithreading - How are Java Thread priorities translated to an OS thread priority?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Indeed, some priority levels can map to the same "native" priority level. Here's the list (based on the Hotspot code in OpenJDK 6):

Solaris

  • 1 ? 0
  • 2 ? 32
  • 3 ? 64
  • 4 ? 96
  • 5 – 10 ? 127

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.

Linux

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

Of note is that on Linux, different thread priorities in Java do map to distinct priority values at native level.

Windows

  • 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...