How can I prevent Java from creating hsperfdata files?
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?
Solution 1:
Try JVM option -XX:-UsePerfData
more info
The following might be helpful that is from link 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.
Solution 2:
Use the JVM option -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).
So the downside of turning off jvmstat instrumentation is that you lose the performance monitoring information.
jvmstat is described here http://java.sun.com/performance/jvmstat/
Here's a thread with someone who is worried that by turning on jvmstat - 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".)
Solution 3:
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.
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=7009828 for more information.