Two Laptop Bag*
The moose likes Threads and Synchronization and the fly likes priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "priority" Watch "priority" New topic
Author

priority

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
http://stackoverflow.com/questions/297804/thread-api-priority-translation-to-os-thread-priority

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


In linux , Is it overhead windows? I mean 10 is the highest priority in windows , But in linux , is it the lowest priority?



Another question:

http://www.javamex.com/tutorials/threads/priority_what.shtml

In this site there is a table that shows priorities in windows

Is this table is similar for all windows versions?

Dose anyone knows priority for different version of windows?(VISTA .7. XP and..)


Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The java thread priority is an abstraction of the OS thread priority. So if you set the java thread priority to the max it will (probably) create a thread with a high OS thread priority.
But the JVM doesn't guaranty that a thread with a high priority will get more cpu time then a thread with a low priority. It depends on the implementation.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thread.setPriority(Thread.MAX_PRIORITY); is equal to thread.setPriority(10); on Windows platform, but what on some other platform? Is that equal for each OS or 10 could be different value on Unix, MacOS or whichever? How does Java map priorities?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Like I pointed about in my previous, apparently unclear, response. The java threading priority is an abstract of the os thread priority. So if you set thread.setPriority(10) then it will get a high priority on windows, linux, mac etc.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
not all JVMs have the same number of priority levels


Is that correct?Do you know any Doc that justify this?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Look it up.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: priority
 
Similar Threads
Thread Starvation
Thread priority
How to run tasks with priority?
Joining Thread, Explanation required
Overloaded varargs param doubt