如何设置Java程序的进程名称? [英] How can I set the process name for a Java-program?

查看:417
本文介绍了如何设置Java程序的进程名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果启动了Java程序,它将在系统进程中监视名称java。许多Java程序很难区分。因此,如果存在方式,设置名称将会很好,这将显示在进程监视器中。我知道这可能在不同的操作系统上有所不同。

If a Java program is started, it get's in the system process-monitor the name java. Many Java-programs are that way hard to distinguish. So it would be nice, if a way exists, to set the name, that will be shown in the process-monitor. I'm aware that this may work different on different Operating Systems.

如果java解释器支持设置名称的开关,就像一个简单的方法,就像这个:

A simple way would be, if the java-interpreter would support a switch to set the name, like this:

java -processname MyProgram -jar MyProgram

但是我找不到这样的开关,所以它可能不存在。用Java设置进程名称的API也没关系。

But I couldn't find such a switch, so it is probably non-existant. An API in Java to set the process-name would be also fine.

那么,你有什么建议吗?

So, so you have any suggestions?

推荐答案

我不知道这是否可行,但您可以使用JDK附带的名为jps的命令行工具。它就像* nix ps ,而只是Java程序。 jps -v 显示您传递给java的所有参数。

I don't know if this is possible, but you could use a command line tool that comes with the JDK called 'jps'. It's like *nix ps, but just Java programs instead. jps -v shows all the arguments you have passed to java.

此外,我看到有人附上通过向args添加未使用的 -Dmyprocessname ,将进程名称添加到其java进程中。

Also, I have seen people attach a "process name" to their java processes by adding an unused -Dmyprocessname to the args.

这篇关于如何设置Java程序的进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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