如何防止 Java 创建 hsperfdata 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/76327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I prevent Java from creating hsperfdata files?
提问by c-had
I'm writing a Java application that runs on Linux (using Sun's JDK). It keeps creating /tmp/hsperfdata_username
directories, which I would like to prevent. Is there any way to stop java from creating these files?
我正在编写一个在 Linux 上运行的 Java 应用程序(使用 Sun 的 JDK)。它不断创建/tmp/hsperfdata_username
目录,我想阻止它。有没有办法阻止java创建这些文件?
采纳答案by Kyle Renfro
Try JVM option -XX:-UsePerfData
尝试 JVM 选项-XX:-UsePerfData
The following might be helpful that is from link https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
以下可能有帮助,来自链接https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
-XX:+UsePerfData
Enables the perfdata feature. This option is enabled by default
to allow JVM monitoring and performance testing. Disabling it
suppresses the creation of the hsperfdata_userid directories.
To disable the perfdata feature, specify -XX:-UsePerfData.
回答by svrist
回答by Stu Thompson
From svrist's link:
来自 svrist 的链接:
The first item in http://java.sun.com/performance/jvmstat/faq.htmlmentions an option which you can turn off to disable the whole suite of features: -XX:-UsePerfData.
http://java.sun.com/performance/jvmstat/faq.html中的第一项提到了一个选项,您可以关闭该选项以禁用整套功能:-XX:-UsePerfData。
回答by SCdF
According to the filed bug reportthere is a work-around:
根据提交的错误报告,有一个解决方法:
This undocumented option will disable the perfdata feature:
-XX:-UsePerfData
这个未记录的选项将禁用 perfdata 功能:
-XX:-UsePerfData
It's worth mentioning that it is a feature though, not a bug. The above work-around just disables the feature.
值得一提的是,它是一个功能,而不是一个错误。上述解决方法只是禁用该功能。
回答by Zweiberg
There is also "-XX:+PerfDisableSharedMem"
option (recommended by Sun) which should cause less performance issues than use of "-XX:-UsePerfData"
option.
还有一个"-XX:+PerfDisableSharedMem"
选项(Sun 推荐)应该比使用"-XX:-UsePerfData"
选项引起更少的性能问题。
回答by Jon Stafford
Use the JVM option -XX:-UsePerfData
.
使用 JVM 选项-XX:-UsePerfData
。
This will not have a negative effect on performance, as some other answers say.
正如其他一些答案所说,这不会对性能产生负面影响。
By default jvmstat instrumentation is turned on in the HotSpot JVM. The JVM option -XX:-UsePerfData
turns it off. If anything, I would speculate, turning off the instrumentation would improve performance (a trivial amount).
默认情况下,在 HotSpot JVM 中启用了 jvmstat 检测。JVM 选项-XX:-UsePerfData
将其关闭。如果有的话,我会推测,关闭仪器会提高性能(微不足道)。
So the downside of turning off jvmstat instrumentation is that you lose the performance monitoring information.
因此,关闭 jvmstat 检测的缺点是您会丢失性能监控信息。
jvmstat is described here http://java.sun.com/performance/jvmstat/
jvmstat 在这里描述http://java.sun.com/performance/jvmstat/
Here's a thread with someone who is worried that by turning onjvmstat - with the option -XX:+UsePerfData
- will hurt performance.
http://www.theserverside.com/discussions/thread.tss?thread_id=33833
(It probably won't since jvmstat is designed to be "'always on', yet has negligible performance impact".)
下面是与某人线程谁是担心通过打开上jvmstat -与选项-XX:+UsePerfData
-将影响性能。
http://www.theserverside.com/discussions/thread.tss?thread_id=33833
(它可能不会,因为 jvmstat 被设计为“始终开启”,但对性能的影响可以忽略不计。)
回答by Mack
Rather than switching it off, change the java.io.tmpdir location. Add -Djava.io.tmpdir=/mydir/somewhere/else/ to your Java startup command and then the file will be somewhere that you control.
与其关闭它,不如更改 java.io.tmpdir 位置。将 -Djava.io.tmpdir=/mydir/somewhere/else/ 添加到您的 Java 启动命令中,然后该文件将位于您控制的某个位置。
Note a comment by @simonc: this only works in a few versions of the JVM and is no longer supported. See http://bugs.sun.com/view_bug.do?bug_id=6447182, http://bugs.sun.com/view_bug.do?bug_id=6938627, http://bugs.sun.com/view_bug.do?bug_id=7009828for more information.
请注意@simonc 的评论:这只适用于 JVM 的几个版本,不再受支持。见http://bugs.sun.com/view_bug.do?bug_id=6447182,http://bugs.sun.com/view_bug.do?bug_id=6938627,http://bugs.sun.com/view_bug.do ?bug_id=7009828了解更多信息。
回答by user6494409
As an addendum to Mack's reply (answered Mar 25 '11 at 17:12), the option java.tmp.dir looks no longer available since Java 8. See the info at: https://bugs.java.com/view_bug.do?bug_id=8189674
作为 Mack 回复的附录(2011 年 3 月 25 日 17:12 回答),选项 java.tmp.dir 自 Java 8 以来似乎不再可用。请参阅以下信息:https://bugs.java.com/view_bug 。 do?bug_id=8189674
So disabling the option using -XX:-UsePerfData seems the only option not to have hsperfdata_* files.
因此,使用 -XX:-UsePerfData 禁用该选项似乎是唯一没有 hsperfdata_* 文件的选项。