有关Java线程和进程优先级的一些问题 [英] Some questions about Java Threads and Process Priorities

查看:99
本文介绍了有关Java线程和进程优先级的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对线程有一个小问题. 在Unix系统上,我们有nice,可用于设置优先级 流程. 好的,在我的系统上,我调用了一些外部进程,但是,我想 为他们设置优先级. 在Unix中,我可以调用其他ProcessBuilder并将其设置为 我想要的进程,但是在Windows中是不可能的.

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.

如果我以某个优先级启动线程,并在ProcessBuilder中使用 它,进程将具有与线程相同的优先级? 还是有其他方法可以做到这一点?

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?

欢呼

推荐答案

在Java中,无法在进程(Process)级别上设置优先级.

There's no way to set priority on a process (Process) level in Java.

如果我以某个优先级启动线程并在其中使用ProcessBuilder,则该进程将具有与线程相同的优先级吗?还是有其他方法可以做到这一点?

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?

该进程将与JVM并排运行,因此它不会继承 threads 优先级.它将由操作系统自行安排.

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.

  • Cross-platform way to change java process priority
  • How to change the priority of a running java process?

这篇关于有关Java线程和进程优先级的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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