I have a Java-process that I would like to run a with background priority in Windows (see here). Is there any easy way to do this?
-
You can set it with setPriority but it is usually treated as a hint and makes next to no difference even when it is not. – Peter Lawrey Oct 01 '12 at 09:04
-
3Have a read of http://stackoverflow.com/questions/2865610/cross-platform-way-to-change-java-process-priority and http://stackoverflow.com/questions/6239142/how-to-change-the-priority-of-a-running-java-process which might help – MadProgrammer Oct 01 '12 at 09:07
1 Answers
Java does not MANDATE any implementation of threading, so the Sun JVM on Windows will work differently to the Sun JVM on Linux, etc. The Windows threading model is very different to Linux threading model. There's nothing even to mandate that a Java thread maps to an underlying OS thread. There isn't (or wasn't when I looked a year ago), any documentation how the JVM implements threading on WINDOWS.
However, in your Windows-specific case, you could POSSIBLY, use JNI or a COM interface to change the process/thread priority. I wouldn't bother though, I think it would be extremely brittle and hard to test. One difficultly is getting the underlying Windows thread ID from the Java Thread object.
What is your background task monitoring/doing? Can you think about your problem differently: what is its essence? The Java concurrency API may help with alternative solutions given clear requirements.

- 1,376
- 2
- 15
- 20