跨平台方式改变java进程优先级 [英] Cross-platform way to change java process priority

查看:112
本文介绍了跨平台方式改变java进程优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在另一个Java应用程序的独立JVM中调用.jar文件,并且它非常耗费CPU,因此它应该以后台优先级运行,以免影响系统的其余部分。有没有任何跨平台的方法来做到这一点?

I need to invoke .jar file in separate JVM from another java application, and it very CPU-consuming, so it should run with background priority in order not to affect the rest of the system. Is there any cross-platform method to do this?

推荐答案

简单的答案是没有可移植的方式来改变优先级Java中的进程(线程 - 是的,进程 - 没有。)

The simple answer is that there is no portable way to change the priority of a Process in Java. (Threads - yes, Processes - no.)

如果你的Java应用程序需要启动一个新的JVM来运行CPU密集型应用程序,那么很可能它已经是不完全便携。例如,您通常需要提供 java 命令(或等效命令)的路径名, -cp 参数(或等效的),系统特定的JVM选项等等。

If your Java application needs to start a new JVM to run the CPU intensive application, then the chances are that it is already not entirely portable. For example, you will typically need to give the pathname of the java command (or equivalent), a -cp argument (or equivalent), system specific JVM options, and so on.

因此,假设启动JVM的命令已经非如果用一个包装器脚本替换命令来执行特定于操作系统的操作来改变已启动进程的优先级,那么这应该是无关紧要的。 (例如,对于UNIX或Linux,您只需使用 nice 即可启动JVM。)

So, assuming that the command to launch the JVM is already non-portable, it should hardly matter if you replace the command with a wrapper script that does OS-specific things to change the priority of the launched process. (For example, for UNIX or Linux you could simply use nice to launch the JVM.)

这篇关于跨平台方式改变java进程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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