I have a small question about threads.
On Unix systems, we have nice
, which can be used to set priorities
processes.
OK, on my system, I call some external processes, however, I would like to
set priority for them.
In unix, I could call other ProcessBuilder and set the nice to
process I want, but in Windows, it is not possible.
If I start a thread with some priority, and use within ProcessBuilder it, the process will have the same priority as thread? Or is there some other way to do this?
Cheers
In Java, a thread's priority is an integer in the range 1 to 10. The larger the integer, the higher the priority. The thread scheduler uses this integer from each thread to determine which one should be allowed to execute.
Explanation: In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call. 5.
There's no way to set priority on a process (Process
) level in Java.
If I start a thread with some priority, and use
ProcessBuilder
within it, the process will have the same priority as thread? Or is there some other way to do this?
The process will run side by side with the JVM, so it will not inherit the threads priority. It will be scheduled on it's own by the operating system.
As stated above, there is no built in cross-platform way of tweaking the priority of a process, but there is a Thread.setPriority(int)
though. So perhaps you could do the work by the external program in a separate thread (instead of starting a new process) and use the setPriority
method on this thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With